openGauss 每日一练第 16 天打卡,我来了!又可以学习,真开心~
学习
今天第 16 课,学习openGauss事务控制。
事务是用户定义的一个数据库操作序列,这些操作要么全做要么全不做,是一个不可分割的工作单位!
课后作业打卡
1.以默认方式启动事务1,修改事务隔离级别,查看transaction_isolation
start transaction;
SET LOCAL TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY;
show transaction_isolation;
END;

2.以读写方式启动事务2,创建新表,修改事务为只读事务,查看transaction_read_only,并向表中插入记录
show transaction_isolation;
START TRANSACTION ISOLATION LEVEL repeatable read READ WRITE;
create table lucifer(id int,name char(20));
SET LOCAL TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY;
show transaction_read_only;
insert into lucifer values(1,'Lucifer');
commit;

3.启动事务3,对表进行增删改查,并用到创建savepoint,回滚savepoint和删除savepoint
START TRANSACTION;
create table lucifer(id int,name char(20));
insert into lucifer values(1,'Lucifer');
select * from lucifer;
SAVEPOINT my_savepoint;
delete from lucifer where id = 1;
ROLLBACK TO SAVEPOINT my_savepoint;
update lucifer set name = 'Lucifer1' where id = 1;
RELEASE SAVEPOINT my_savepoint;
COMMIT;
select * from lucifer;

4.清理数据
drop table lucifer;
写在最后
今天的作业打卡结束!🎉
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




