mysql视图和存储过程
视图常用:
create or replace view 视图名 as select * from 表名 where 条件 with( CASCADED CHECK OPTION级联检查条件/LOCAL CHECK OPTION);
-- create or replace view `u_10` as select id,name,phone,uuid from users where id <= 10;
-- create or replace view `u_20` as select id,name,phone,uuid from u_10 where id <= 20 with CASCADED check OPTION;
-- create or replace view `u_20` as select id,name,phone,uuid from u_10 where id <= 20 with LOCAL check OPTION;
insert into `u_20` values('13','lisi','13211113313','13');
存储过程:
查看系统变量:系统变量厍变量(GLOBAL)会话变量(SESSION)
show [SESSION|GLOBAL] variables;查看所有系统变量;
show [SESSION|GLOBAL]variables like '......'
show @@[SESSION|GLOBAL] 系统变量名
设置系统变量:
set [SESSION|GLOBAL] 系统变量名=值;
set @@[SESSION|GLOBAL] 系统变量名=值
是事先经过编译并存储在数据库中的一段SQL语句的集合;
特点:封装、复用、可以接收参数和返回数据、减少网络交替提升效率
--创建:(在命令行中执行要设置delimiter $$为结束符,;号不在未结束符)
create procedure 存储过程名称([参数])
begin
sql语句;
end;
--调用:
call 存储过程名();
--查看
查看系统表:select * fromINFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='itcast';
show create procedure 存储过程名;
--删除
drop procedure if exists 存储过程名;
