云数据库 GAUSSDB-ABORT:示例

时间:2024-11-13 14:46:50

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--创建表customer_demographics_t1。
gaussdb=# CREATE TABLE customer_demographics_t1
(
    CD_DEMO_SK                INTEGER               NOT NULL,
    CD_GENDER                 CHAR(1)                       ,
    CD_MARITAL_STATUS         CHAR(1)                       ,
    CD_EDUCATION_STATUS       CHAR(20)                      ,
    CD_PURCHASE_ESTIMATE      INTEGER                       ,
    CD_CREDIT_RATING          CHAR(10)                      ,
    CD_DEP_COUNT              INTEGER                       ,
    CD_DEP_EMPLOYED_COUNT     INTEGER                       ,
    CD_DEP_COLLEGE_COUNT      INTEGER
)
DISTRIBUTE BY HASH (CD_DEMO_SK);

--插入记录。
gaussdb=# INSERT INTO customer_demographics_t1 VALUES(1920801,'M', 'U', 'DOCTOR DEGREE', 200, 'GOOD', 1, 0,0);

--开启事务。
gaussdb=# START TRANSACTION;

--更新字段值。把cd_education_status字段值更新为Unknown。
gaussdb=# UPDATE customer_demographics_t1 SET cd_education_status= 'Unknown';

--终止事务,上面所执行的更新会被撤销掉。
gaussdb=# ABORT; 

--查询数据。发现cd_education_status字段的值未被修改成Unknown。
gaussdb=# SELECT * FROM customer_demographics_t1 WHERE cd_demo_sk = 1920801;
cd_demo_sk | cd_gender | cd_marital_status | cd_education_status  | cd_purchase_estimate | cd_credit_rating | cd_dep_count | cd_dep_employed_count | cd_dep_college_count 
------------+-----------+-------------------+----------------------+----------------------+------------------+--------------+-----------------------+----------------------
    1920801 | M         | U                 | DOCTOR DEGREE        |                  200 | GOOD             |            1 |                     0 |                    0
(1 row)

--删除表。
gaussdb=# DROP TABLE customer_demographics_t1;
support.huaweicloud.com/distributed-devg-v8-gaussdb/gaussdb-12-0476.html