COMMIT is used to change the data permanently by commits the database changes occur in the current transaction and made that changes permanent.
In DB2, the COMMIT statement is used to permanently save any changes made during the current transaction. When you issue a COMMIT, it finalizes the changes made by the SQL statements within the transaction, making them permanent in the database. This means that the changes are made visible to other transactions, and they are durable even if a system failure occurs.
The COMMIT statement essentially marks the end of a transaction, and it ensures the atomicity, consistency, isolation, and durability (ACID properties) of the database transactions.
For example:
-- Start of transaction
BEGIN
-- SQL statements making changes to the database
UPDATE table1 SET column1 = 'new value' WHERE condition;
INSERT INTO table2 (column1, column2) VALUES ('value1', 'value2');
— Committing the changesCOMMIT;
— End of transaction
In this example, the changes made by the UPDATE and INSERT statements will only become permanent in the database when the COMMIT statement is executed. If there is an issue or if the transaction needs to be rolled back, you can use the ROLLBACK statement instead of COMMIT to undo the changes made during the current transaction.