一分钟做网站,wordpress调用优酷视频播放器,做篮球管理网站的步骤,网站建设分几类视图#xff5c;存储过程 视图视图基本使用使用视图视图进阶 存储过程创建存储过程存储过程进阶存储过程参数循环结构 视图
视图是虚拟存在的表 表头下的数据在真表里 表头下的数据存储在创建视图时 在select命令访问的真表里 优点#xff1a;
安全数据独立简单 用户无需关… 视图存储过程 视图视图基本使用使用视图视图进阶 存储过程创建存储过程存储过程进阶存储过程参数循环结构 视图
视图是虚拟存在的表 表头下的数据在真表里 表头下的数据存储在创建视图时 在select命令访问的真表里 优点
安全数据独立简单 用户无需关心数据内部
视图基本使用
create view v1 as select name from tarena.user除了视图每个表都会存在两个文件 查看所有表的状态
show table status ; 查看创建视图具体select命令
show create view 视图名;使用视图
insert
insert into tarena.v11 vlaues (xxx,2002);delete
delete from tarena.v11 where name in (xxx,yyy)update
# 物理表 会跟着变
update tarena.v11 set uid1001 where nameroot视图进阶 可以通过视图修改数据限制 限制方式如下
with check option local 首先满足自身的限制同时满足基表的限制 local
mysql create view v31 as select name , uid from tarena.user where uid 100;
mysql create view v45 as select name,uid from v31 where uid10 with local check option;
mysql update v45 set uid800 where nameftp
# 虽然超出基表v31限制但是还是改成了 因为基表没有加限制# 修改视图v31 加修改限制
mysql create or REPLACE view v31 as select name,uid from tarena.user where uid 100 with check option;
mysql update v45 set uid6 where namesshd; 没有满足自身限制
mysql update v45 set uid600 where namesshd; 没有满足基表v31的限制cascaded 满足视图自身限制即可默认值
mysql create view v21 as select name,uid from tarena.user where uid10 with check option# 此时的限制条件是uid10 如果改小于10 会失败
mysql update v21 set uid9 where nameroot; # 会失败存储过程
存储过程就是mysql服务里的脚本。mysql存储过程 是登陆mysql服务之后编写的脚本 是由一条或多条sql命令组成存放在mysql库下的表里。避免重复的sql操作。
写好的存储过程 会存放在mysql库下的proc表里
创建存储过程
命令行结束符 修改为//
delimiter //
---
create procedure 库名.存储过程名(列表参数)
begin一组合法的sql命令
end
//
--
delimiter ;查看已创建的存储过程
select db,name,type,body from mysql.proc where typeprocedure执行存储过程
call 库名.存储过程名 创建的存储过程没有参数
call 库名.存储过程名(参数) 删除存储过程
drop procedure 库.存储过程名; 不加括号 无论有无参数存储过程进阶 用户自定义变量 用户变量 局部变量begin/end语句块中
存储过程参数
调用参数时名称前也不需要 create procedure 名称(类型 变量名 数据类型 , 类型 变量名 数据类型,…)
delimiter //
create procedure tarena.p3()
begin
select name from tarena.user where nameftp;
end //
delimiter ;delimiter //
create procedure tarena.p4(in dept_no int)
begin
select dept_id,count(name) from employees where dept_iddept_no
group by dept_id
end //
delimiter;## 调用
call tarena.p4(3)out参数的作用 delimiter //
create procedure tarena.p5(in emp_name varchar(10),out mail varchar)
begin
select email into mail from employees where nameemp_name;
end //
delimiter ;# 调用
call tarena.p5(bob,x)inout参数 既有in参数的功能 又有out参数的功能
delimiter //
create procedure tarena.myadd(inout i int)
begin
set ii100;
end //
delimiter ;
set x 8
set y 101
call tarena.myadd(x);
call tarena.myadd(y);
select x,y循环结构
if 格式一
IF 条件 THEN语句;
END IF;格式二
IF 条件 THEN语句1;
ELSEIF 条件2 THEN语句2;
ELSE语句3;
END IF;解决乱码问题
alter database tarena default character set utf8;
# 查看库使用的字符集
show create detabase tarena \G
show create table tarena.departments \G
# 修改完重新创建存储过程 就好使了case 语法格式
CASE 变量表达式字段
WHEN 判断的值1 THEN 返回值1;
WHEN 判断的值2 THEN 返回值2
... ...
ELSE 返回值n;
END CASE;案例
delimiter //
create procedure tarena.deptype_pro2(IN no int ,OUT dept_type varchar(5))
begin
declare type varchar(5);
select dept_name into type from departments where dept_idno;
case type
when 运维部 then set dept_type技术部;
else set dept_type非技术部;
end case;
end //
delimiter ;
# 使用自定义变量接受out参数的值
call tarena.deptype_pro(1,t);
# 查看自定义变量t的值
select t;循环语法
标签名WHILE 循环条件 DO循环体;
END WHILE 标签名# loop循环 只要不人为结束 就一直执行下去
LOOP循环体;
END LOOP
# repeat 循环至少循环一次
repeat循环体;
UNTILE 循环结束条件
end repeat循环结构控制语句在循环条件满足的情况下控制循环的执行
break 结束循环ITERATE 相当于continue 结束当前循环并开始下次循环 注意要给循环加标签 就是给循环起一个名字才能使用 案例
delimiter //
create procedure tarena.while_pro(IN i int)
begin
declare j int default 1;
while j i doinsert into tarena.departments(dept_name) values(hr);set jj1;
end while;
end //
delimiter ;
# 调用
mysql call tarena.while_pro(3);show processlist 相当于 ps -aux 案例
delimiter //
create procedure tarena.while_pro3(IN i int)
begindeclare j int default 0;a:while ji doset jj1;if mod(j,2)0 then iterate a;end if ;insert into tarena.departments(dept_name) value(concat(hr,i))end while a;
end //
delimiter ;
# 调用
call tarena.while_pro3(10);
select * from tarena.departments;
文章转载自: http://www.morning.fkmyq.cn.gov.cn.fkmyq.cn http://www.morning.xbzfz.cn.gov.cn.xbzfz.cn http://www.morning.hwzzq.cn.gov.cn.hwzzq.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.tpwrm.cn.gov.cn.tpwrm.cn http://www.morning.dnydy.cn.gov.cn.dnydy.cn http://www.morning.qrqcr.cn.gov.cn.qrqcr.cn http://www.morning.jpfpc.cn.gov.cn.jpfpc.cn http://www.morning.txqsm.cn.gov.cn.txqsm.cn http://www.morning.pangucheng.cn.gov.cn.pangucheng.cn http://www.morning.kgphd.cn.gov.cn.kgphd.cn http://www.morning.xgchm.cn.gov.cn.xgchm.cn http://www.morning.lmyq.cn.gov.cn.lmyq.cn http://www.morning.jyfrz.cn.gov.cn.jyfrz.cn http://www.morning.ggtgl.cn.gov.cn.ggtgl.cn http://www.morning.gmmyn.cn.gov.cn.gmmyn.cn http://www.morning.lbqt.cn.gov.cn.lbqt.cn http://www.morning.dqwykj.com.gov.cn.dqwykj.com http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.qbgdy.cn.gov.cn.qbgdy.cn http://www.morning.drndl.cn.gov.cn.drndl.cn http://www.morning.hrjrt.cn.gov.cn.hrjrt.cn http://www.morning.grnhb.cn.gov.cn.grnhb.cn http://www.morning.dpruuode.cn.gov.cn.dpruuode.cn http://www.morning.bzjpn.cn.gov.cn.bzjpn.cn http://www.morning.htbbp.cn.gov.cn.htbbp.cn http://www.morning.rlhgx.cn.gov.cn.rlhgx.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.knjj.cn.gov.cn.knjj.cn http://www.morning.xbkcr.cn.gov.cn.xbkcr.cn http://www.morning.gmysq.cn.gov.cn.gmysq.cn http://www.morning.hchrb.cn.gov.cn.hchrb.cn http://www.morning.ckctj.cn.gov.cn.ckctj.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn http://www.morning.pjxlg.cn.gov.cn.pjxlg.cn http://www.morning.hsjfs.cn.gov.cn.hsjfs.cn http://www.morning.pqwhk.cn.gov.cn.pqwhk.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.xmnlc.cn.gov.cn.xmnlc.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.pkdng.cn.gov.cn.pkdng.cn http://www.morning.rrgm.cn.gov.cn.rrgm.cn http://www.morning.lqgtx.cn.gov.cn.lqgtx.cn http://www.morning.xzrbd.cn.gov.cn.xzrbd.cn http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn http://www.morning.chbcj.cn.gov.cn.chbcj.cn http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn http://www.morning.bpttm.cn.gov.cn.bpttm.cn http://www.morning.wmqrn.cn.gov.cn.wmqrn.cn http://www.morning.zypnt.cn.gov.cn.zypnt.cn http://www.morning.dyxlm.cn.gov.cn.dyxlm.cn http://www.morning.lmhh.cn.gov.cn.lmhh.cn http://www.morning.chmkt.cn.gov.cn.chmkt.cn http://www.morning.rwrn.cn.gov.cn.rwrn.cn http://www.morning.yfnjk.cn.gov.cn.yfnjk.cn http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.wchcx.cn.gov.cn.wchcx.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.xjnw.cn.gov.cn.xjnw.cn http://www.morning.mhmsn.cn.gov.cn.mhmsn.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.jkzq.cn.gov.cn.jkzq.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.thrcj.cn.gov.cn.thrcj.cn http://www.morning.qhkx.cn.gov.cn.qhkx.cn http://www.morning.rxxdk.cn.gov.cn.rxxdk.cn http://www.morning.ryywf.cn.gov.cn.ryywf.cn http://www.morning.nmqdk.cn.gov.cn.nmqdk.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.wcft.cn.gov.cn.wcft.cn http://www.morning.jyyw.cn.gov.cn.jyyw.cn http://www.morning.fdrwk.cn.gov.cn.fdrwk.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.qsszq.cn.gov.cn.qsszq.cn http://www.morning.nfgbf.cn.gov.cn.nfgbf.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.bfybb.cn.gov.cn.bfybb.cn