- ~
1.1建立数据库数据库
create database 数据库名 character set 字符集 collate 校对规则;
1.2查看数据库code
show databases show create database 数据库名
1.3修改数据库的字符集排序
alter database 数据库名 character set 字符集;
1.4删除数据库table
drop database 数据库名;
2.1建立表date
create table 表名(列名 类型 约束,列名 类型 约束....)
2.2查看表select
show tables; show create table 表名; desc 表名;
2.3修改表(除了修改表名以外,都是以alter table 表名)
2.3.1增长一列数据
alter table 表名 add 列名 类型 约束;
2.3.2删除一列查询
alter table 表名 drop 列名;
2.3.3修改某列的类型及约束tab
alter table 表名 modify 列名 类型 约束;
2.3.4修改某列的列名di
alter table 表名 change 旧列名 新列名 类型 约束;
2.3.5修改表名
rename table 旧表名 to 新表名;
2.4 删除表
drop table 表名;
3.1插入数据
insert into 表名(列,列,列...) values(值,值,值...) insert into 表名 values(值,值,值...)
3.2更新数据
update 表名 set 列名=值,列名=值 where 条件
3.3 删除数据
delete from 表名 where 条件 truncate table 表名; 先将表删除,而后建立一张如出一辙的空表
3.4 查询数据
3.4.1查询全部数据
select * from 表名
3.4.2查询某些列的数据
select 列名,列名 from 表名
3.4.3去重查询,只有当要查询的字段都相同才能去重
select distinct 列名,列名 from 表名;
3.4.4别名查询
select 列名 as 别名 from 表名
3.4.5运算查询
select price+200 from star;
3.4.6排序查询(asc表示升序,desc表示降序)
select * from 表名 order by 列名
3.4.7条件查询
比较运算符:>,<,>=,<=,=,<>(!=) between and in(set) like 用于模糊查询,占位符%表示占0-n位,_表示占一位 逻辑运算符 and,or,not