数据库
表(table)
-
创建表
create table 表名( 字段名1 数据类型 auto_increment, //自动递增 字段名2 数据类型 not null, //不为空 字段名3 varchar (长度) default '...', // 默认'....' ... ... primary key(字段名1), //设置主键 Constraint 外键名 Foreign key(当前表字段名) references 表名 (表主键字段名) );
-
增
insert into 表名 values(值1,值2,....); insert into 表名(字段名1,字段名2...)values(值1,值2...);
-
删
delete from 表名 where 条件;
-
改
update 表名 set 字段=新值 where 条件;
-
查
Select distinct 属性,聚集函数 from 表名 where 条件 group by 属性 having 条件 order by 属性 limit n,m;
索引(index)
-
展示
Show index from 表名;
-
创建
-- 普通索引 create index 索引名 on 表名(字段名); -- 唯一性索引 create unique index 索引名 on 表名(列名);
-
删除
Drop index 索引名 on 表名;
-
explain
-
type —> const
—> all
-
rows
-
视图(view)
-
展示
show tables;
-
展示创建过程
show create view 视图名;
-
创建
create view 视图名 as select 的SQL语句;
-
更改
create or replace view 视图名 as select 的SQL语句;
-
删除
Drop view 视图名;
存储过程(procedure)
-
创建
create procedure 存储过程名([in][out][inout] 参数 datatype) Begin sql语句集 ... ... end -- 修改结束符号 Delimiter #
-
调用
call 存储过程名();
-
删除
Drop procedure if exists 存储过程名;
-
参数分类
-
In(默认)
-
Out
-
In、Out
create procedure p_e(in n1 int, out n2 int) Begin select sscore into n2 from t_student where sid=n1; end call p_e(1220,@i); select @i;
-
Inout
create procedure P_k(inout n1 int) Begin select sscore into n1 from t_student where sid=n1; end set @g=1203; call p_k(@g); select @g;
-
-
展示存储过程
-- 名字 select name from mysql.proc status where db='数据库名'; -- 详细信息 show procedure status where db='数据库名';
触发器(trigger)
-
展示
show triggers like '表名';
-
创建
create trigger 触发器名 after/before insert/update/delete on 被监听的表 for each row SQL语句(增删改,不包含查)
-
删除
drop trigger 触发器名;
范式(NF)
- 第一范式
- 列不能再分
- 第二范式
- 部分依赖
- 第三范式
- 传递依赖