非原创
本文转自https://github.com/a415432669/-front_end_notebook/tree/master/Node/day6/%E6%96%87%E6%A1%A3
视图
- 对于复杂的查询,在多次使用后,维护是一件非常麻烦的事情
- 解决:定义视图
- 视图本质就是对查询的一个封装
- 定义视图
create view stuscore as
select students.*,scores.score from scores
inner join students on scores.stuid=students.id;
- 视图的用途就是查询
select * from stuscore;
操作
-- 查询视图内容等同于查询表操作
SELECT * from bookallinfo where cataory = '历史传记';
-- 视图实现模糊查找
SELECT * from bookallinfo where bookname like "%小%";
-- 更新多字段
UPDATE booktable SET bookname = "小时代1",authorid=0,score = NULL where id = 2;
-- 删除
-- 逻辑删除和物理删除
-- 逻辑删除小时代书
UPDATE booktable set isdelete = "true" where id = 2
-- 物理删除
-- DELETE from booktable WHERE bookname = "鬼吹灯"
DELETE from booktable
逻辑删除:就是设置isdelete = "true",用户信息还在数据库中,还是可以给你发送信息