Updated on 2025-10-23 GMT+08:00

COMMIT

Description

Provides COMMIT to commit all operations of a transaction.

Precautions

Only the creator of the transaction or system administrators can run the COMMIT statement. The creation and commit operations do not have to be in different sessions.

Syntax

COMMIT [ WORK | TRANSACTION ];

Parameters

  • COMMIT

    Commits the current transaction and makes all changes made by the transaction become visible to others.

  • WORK | TRANSACTION

    Specifies an optional keyword, which has no effect except improving readability.

Examples

-- Create a schema.
m_db=# CREATE SCHEMA tpcds;

-- Create a table.
m_db=# CREATE TABLE tpcds.customer_demographics_t2
(
    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
);

-- Start a transaction.
m_db=# START TRANSACTION;

-- Insert data.
m_db=# INSERT INTO tpcds.customer_demographics_t2 VALUES(1,'M', 'U', 'DOCTOR DEGREE', 1200, 'GOOD', 1, 0, 0);
m_db=# INSERT INTO tpcds.customer_demographics_t2 VALUES(2,'F', 'U', 'MASTER DEGREE', 300, 'BAD', 1, 0, 0);

-- Commit the transaction to make all changes permanent.
m_db=# COMMIT;

-- Query data.
m_db=# SELECT * FROM tpcds.customer_demographics_t2;

-- Delete the tpcds.customer_demographics_t2 table.
m_db=# DROP TABLE tpcds.customer_demographics_t2;

-- Delete the schema.
m_db=# DROP SCHEMA tpcds;

Helpful Links

ROLLBACK