DCL语句和TCL语言

1.DCL语句

1.创建用户

create user 'zhangsan'@'localhost' identified by '123456';

2.授权

授予所有权限

grant all on *.* to 'zhangsan'@'localhost';

撤销授权

revoke all on *.* from 'zhangsan'@'localhost';

授予DML的权限

grant select,update,insert on scott.* to 'zhangsan'@'localhost' with grant option;

 

3.查看用户的权限

show grants for 'zhangsan'@'localhost'

 


2.TCL 语言 (事务控制语言)

Transaction主要是对insert ,update,delete的控制

事务:一系列不可分割的完整的操作

 

事务的特性:  ACID

A 原子性[Atomicity]

   事务中的多个操作要么同时成功,要么同时失败。

   只要有一个失败,全部回滚到事务开始前的状态。

 

C 一致性[Consistency]   

  在事务开始之前和事务结束以后,数据库的完整性没有被破坏。这表示写入的资料必须完全符合所有的预设规则。

 

I 隔离性[Isolation]

多个事务可以并发执行,隔离性可以防止事务交叉执行而导致的数据不一致。

 

D 持久性[Durability]

事务提交之后,数据的改变是持久性的

 

 

1.开始事务

start transaction;


2.

  update emp2 set sal=1000 where empno=6666;

  update emp2 set sal=1300 where empno=7934;

3.如果执行出错需要回滚

  rollback;

 

 4.事务执行没有问题,就提交事务

  commit;

开始事务

start transaction;

update emp2 set sal=1000 where empno=6666;

设置保存点

savepoint aa;

update emp2 set sal=1300 where empno=7934;

  回滚到指定的保存点

   rollback to aa;

如果没有指定保存点,就回滚到事务开始前的状态

 

  rollback;

 

发布了52 篇原创文章 · 获赞 38 · 访问量 2489

猜你喜欢

转载自blog.csdn.net/weixin_44364444/article/details/104031323