sql作为一门古老的语言,学习起来性价比超高!几十年都不用更新!本节内容为进阶高级复习题!
create database 数据库名
create table 表名 (
字段1 varchar(255) 约束,
字段2 类型 约束,
primary key (字段1)
...
)
not null 不能为null
unique 唯一
primary key 主键
foreign key 外键
default 默认
check 选择
drop table 表名
drop database 数据库名
只清空:
delete from 表
truncate table 表
select top 5 字段 from 表
select 字段 from 表 limit 5
select 字段 from 表 where 字段2 like "%结尾"
%代表任意字符
not like 代表不包含这个模糊搜索
% 代表0个或多个字符
_ 代表一个字符
REGEXP [1,2,'a'] 代表内部任何单一字符
REGEXP ^[A-H] 不包含任何单一大写字母
REGEXP ![^字符列表] 不包含任何单一字符
select 字段 from 表 where 字段 in (值1,值2)
not in 不在
select 字段 from 表 where 字段 between 值1 and 值2
not between 不属于
select 字段 as 新字段名 from 表
select 字段 from 表 as 新表名

select * from 表1 inner join 表2 on 表1.字段1 = 表2.字段2


select * from 表1 lect/right join 表2 on 表1.字段1=表2.字段2

select * from 表1 full join 表2 on 表1.字段1=表2.字段2
可以用在左右全中,如left outer join,可以返回不包含的内容

在 on 后加where
如 select * from 表1 left join 表2 on 表1.字段1=表2.字段2 where 表2.字段 is null
select * from 表1 union select * from 表2
select * from 表1 union all select * from 表2
create table 新表 as select * form 旧表
insert into 新表 select * from 旧表
insert into 新表 (字段名) select * from 旧表
create index 索引名 on 表名 (字段名-可不写)
创建不允许值重复的唯一索引
create unique index 索引名 on 表名
alert table 表名 drop index 索引名
好了,本节结束!