DQL:
数据查询语言(select...)
DML:
数据操纵语言(增删改)
insert 增
delete 删
update 改
DDL:
数据定义语言(操作表的结构,不是操作表的数据)
create 新建
drop 删除
update 改
操作表中的数据data。
TCL:
事务控制语言
事务提交:commit;
事务回滚:rollback;
DCL:
数据控制语言
grant 授权
revoke 撤销
创建数据库
create database student;
删除数据库
drop database student;
创建表
create table stu(
id int unsigned primary key,
name varchar(20) not null default ' ',
gender varchar(2) not null default '男'
);
删除表
drop table stu;
插入数据
insert into stu values(1,'zhangsan','男'),(2,'lisi','女');
查看数据
select * from stu;
更新数据
update stu set name = 'zhangsan';
update stu set name = 'lisi' where name = 'zhangsan';
删除数据
delete from stu where name = 'lisi';
复制表结构
create table stu2 like stu;
复制表数据
insert into stu2 select * from stu;
清空表数据
truncate(也可用delete) table stu2;
模糊查询
'%a' //以a结尾的数据
'a%' //以a开头的数据
'%a%' //含有a的数据
'_a_' //三位且中间字母是a的
'_a' //两位且结尾字母是a的
'a_' //两位且开头字母是a的
排序(多段排序order by name asc,ename asc;只有name相等才会考虑ename)
select * from stu order by name desc(升序默认asc);
union的使用
select * from stu union all select * from stu2;(union去除重复的)
学习资料:菜鸟教程mysql教程,csdn,b站老杜
数据库语言不区分大小写,以分号结尾;