postgersql-事务
声明:本PostgreSQl实用指南系列为刘兴(http://deepfuture.iteye.com/)原创,未经笔者授权,任何人和机构不能转载mydb=# select * from student;
name | age | city | sex
------------+-----+------+-----
deepfuture | 20 | 1 |
未来 | 20 | 2 |
张三 | 21 | 1 |
干哈 | 18 | 2 |
艾丝凡 | 18 | 3 |
(5 rows)
开始事务
mydb=# begin;
BEGIN
mydb=# update student set sex='man' where city=2;
UPDATE 2
设置回滚保存点
mydb=# savepoint my_sp;
SAVEPOINT
mydb=# update student set sex='woman' where city=3;
UPDATE 2
取消对 city=3的操作,回到保存点
mydb=# rollback to my_sp;
ROLLBACK
更新
mydb=# update student set sex='woman' where city=1;
UPDATE 2
提交
mydb=# commit;
COMMIT
mydb=# select * from student;
name | age | city | sex
------------+-----+------+-------
艾丝凡 | 18 | 3 |
萨芬 | 19 | 3 |
未来 | 20 | 2 | man
干哈 | 18 | 2 | man
deepfuture | 20 | 1 | woman
张三 | 21 | 1 | woman
(6 rows)
mydb=#
页:
[1]