创建用户
create user <用户名> identified by '<密码>';
删除用户
drop user <用户名>;
用户权限
// 授权
grant all on <数据库名>.* to <用户名>@'localhost' identified by '<密码>'
with grant option; //授予该用户授权的权限
// 撤权
revoke all on <数据库名>.* from <用户名>;
// 更新权限
flush privileges;
触发器
// 创建触发器
create trigger <触发器名>
<before|after> <insert|update|delete>
on <表名>
for each row
<触发主体>;
// 删除触发器
drop trigger <触发器名>;
索引
// 创建索引
create index <索引名> on <表名>(<列名>);
// 显示索引
show index <索引名> from <表名>;
// 删除索引
drop index <索引名> on <表名>;
游标
// 定义一个游标
declare <游标名> cursor for <查询语句>; //mysql
declare cursor <游标名> is <查询语句>; //oracle
// 打开游标
open <游标名>;
// 使用游标
fetch <游标名> into <变量名[,变量名……]>; //将一行记录放入到变量中,变量需提前声明
// 关闭游标
close <游标名>;
存储过程
概念:存储过程是一组存放在数据库中SQL语句,默认与当前数据库绑定,若要与其它数据库绑定,需在创建时在存储过程名前加数据库名。
// 创建存储过程
// mysql
create procedure <存储过程名>(in <输入参数名> <参数类型>, out <输出参数名> <参数类型>)
begin
<存储过程主体>
end;
// oracle
create or replace procedure <存储过程名>(<输入参数名> in <参数类型>, <输出参数名> out <参数类型>) as
begin
<存储过程主体>
end;
//执行存储过程
call <存储过程名>(<参数列表>);