什么是高级?这就叫高级—openGauss(25)

16 阅读1分钟

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/

示例

假设存在表customer_t1 ,数据内容如下:

openGauss=# SELECT * FROM customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
          3769 | hello         | Grace        |             |   1000
          3769 |               | Grace        |             |
          3769 | hello         |              |             |
          6885 | maps          | Joes         |             |   2200
          4321 | tpcds         | Lily         |             |   3000
          9527 | world         | James        |             |   5000
(6 rows)

开启一个事务,并从表中删除amount为1000的行,最后使用ROLLBACK命令撤销所有的更改。

openGauss=# START TRANSACTION;
openGauss=# DELETE FROM customer_t1 WHERE amount = 1000;
openGauss=# ROLLBACK;

查看表customer_t1,amount为1000的行仍然存在。

openGauss=# select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
          3769 | hello         | Grace        |             |   1000
          3769 |               | Grace        |             |
          3769 | hello         |              |             |
          6885 | maps          | Joes         |             |   2200
          4321 | tpcds         | Lily         |             |   3000
          9527 | world         | James        |             |   5000
(6 rows)

开始另一个事务,从表中删除amount=1000的记录,最后使用COMMIT命令提交所有的更改。

--开启一个事务,设置事务的隔离级别为READ COMMITTED,访问模式为READ ONLY。
openGauss=# BEGIN;
openGauss=# DELETE FROM customer_t1 WHERE amount = 1000;
openGauss=# COMMIT;

查询表customer_t1,amount=1000的记录已经被删除。

openGauss=# select * from customer_t1;
 c_customer_sk | c_customer_id | c_first_name | c_last_name | amount
---------------+---------------+--------------+-------------+--------
          3769 |               | Grace        |             |
          3769 | hello         |              |             |
          6885 | maps          | Joes         |             |   2200
          4321 | tpcds         | Lily         |             |   3000
          9527 | world         | James        |             |   5000
(5 rows)

#openGauss #入门 #安装 #数据库 #开源

知识来源:docs-opengauss.osinfra.cn/zh/