MySQL(三)

2018-10-23  本文已影响0人  w_wm_m

视图

     视图的本质是对复杂查询语句的封装。

     创建视图

create view v_1 as
select students.name,subjects.title,scores.score
from scores
inner join students on scores.stuid = students.id
inner join subjects on scores.subid = subjects.id;

     语法:

create view 视图名 as
要封装的select语句

     修改视图

alter view v_1 as
select students.name,subjects.title,scores.score
from scores
inner join students on scores.stuid = students.id
inner join subjects on scores.subid = subjects.id
where students.isdelete = 0;

     使用视图

select * from 视图名; //select * from v_1;

事务

原子性(Atomicity):要么全部完成,要么均不执行
一致性(Consistency):几个并行的事务,其执行结果保持一致
隔离性(Isolation):事物执行不受其他事务干扰,事务执行的中间结果对其他事务透明
持久性(Durability):已提交的事务系统必须保证事务对数据库的改变不被丢失

事务.png
begin;
update/insert/delete语句
commit/rollback;

     使用begin开启一个事务,将修改的数据存入内存级的临时表中,最后使用commit将临时表中的数据提交给真正的表,也可以使用rollback回滚为之前的状态,忽略临时表中暂存的数据。

索引

create index 索引名 on 表名(字段名(length),...);//如果是多列索引在ho
drop index 索引名 on 表名;
上一篇 下一篇

猜你喜欢

热点阅读