Home > Database > Mysql Tutorial > How to permanently record changes made in the current transaction in a MySQL database?

How to permanently record changes made in the current transaction in a MySQL database?

王林
Release: 2023-08-29 18:57:06
forward
1285 people have browsed it

How to permanently record changes made in the current transaction in a MySQL database?

We can use the COMMIT command to permanently record the changes made in the current transaction in the MySQL database. Suppose we run some DML statements and update some data objects, then the COMMIT command will permanently record these updates in the database.

Example

mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Marks Values(1, 'Aarav','Maths',50);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Marks Values(2, 'Harshit','Maths',55);
Query OK, 1 row affected (0.00 sec)

mysql> COMMIT;
Query OK, 0 rows affected (0.06 sec)
Copy after login

In this example, the COMMIT statement will explicitly end the transaction, and the changes will be saved, that is, permanently recorded in the database.

mysql> SELECT * FROM Marks;
+------+---------+---------+-------+
| Id   | Name    | Subject | Marks |
+------+---------+---------+-------+
| 1    | Aarav   | Maths   | 50    |
| 2    | Harshit | Maths   | 55    |
+------+---------+---------+-------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How to permanently record changes made in the current transaction in a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template