本文共 2278 字,大约阅读时间需要 7 分钟。
SQL(Structure Query Language,结构查询语言)是一种标准化的关系型数据库查询语言,由美国国家标准局(ANSI)确定为关系型数据库的美国标准,后被国际化标准组织(ISO)采纳为关系型数据库的国际化标准。
各数据库厂商都支持ISO的SQL标准,也在标准基础之上做了扩展。SQL提供了CRUD操作的实现,即Create、Read、Update、Delete四个基本操作。根据功能划分,SQL可以分为以下几类:
用于定义数据库对象:包括库、表、列等。
用于对数据库记录(数据)进行增删改操作。
用于定义数据库安全权限和访问级别。
用于查询数据库记录(数据)。
create database mydb1;create database mydb1 character set utf8mb4;create database mydb1 set GBK collate gbk_chinese_ci;
show databases;show create database mydb1;
alter database mydb1 character set utf-8;
drop database mydb1;
use mydb2;
create table card( cardid int not null, cardnum varchar(20), regDate date);
show tables;desc cardinfo;
drop table cardinfo;
alter table cardinfo add delDate date;
alter table cardinfo change cardnum cardnum varchar(30);
alter table cardinfo drop regDate;
alter table card rename CardInfo;
alter table 表名 character set utf-8;
insert into 表名(列名) values(数据值);insert into student(stuname,stuage,stusex,birthday) values('张三1',18,'a','2000-1-1');
insert into student values('李四',12,'1111',189.98,'2000-1-1','男','2007-1-1');
insert into student(stuname,stuage,stusex,birthday) values('张三3',18,'a','2000-1-1'), ('张三4',18,'a','2000-1-1');
update 表名 set 列名1=值1,列名2=值2... where 条件;update student set stuname='张三', stuage=18 where id=1;
delete from 表名 [where 条件];delete from student where id=1;
truncate table 表名;
delete
用于删除数据,表结构不变,数据可恢复。truncate
直接清空表,执行速度快,删除的数据不可恢复。SQL提供多种日期类型:
date
:yyyy-MM-dd
time
:hh:mm:ss
datetime
:yyyy-MM-dd hh:mm:ss
获取当前时间:now()
+
、-
、*
、/
、%
=
从右向左赋值
and
、or
、not
>
, <
, >=
, <=
, !=
, <>
, =
create user 用户名@localhost identified by 密码;create user test@'%' identified by 'test@123';
grant select,insert,delete,update,create on test_db.* to test@'%';grant all on *.* to test@localhost;
show grants for test@'%';
转载地址:http://mrtxz.baihongyu.com/