Write a simple INSERT statement in SQL Server and submit:
INSERT into EMP (empno,ename) VALUES (2, ' Dan ');
Commit
Result Error:
Message 3902, Level 16, State 1, row 3rd COMMIT TRANSACTION request does not have a corresponding BEGIN TRANSACTION.
The reason for the error: It is true to write this in Oracle, but this SQL Server environment. Grammar needs to change.
Solution:
It should be written like this:
BEGIN TRANSACTION;
INSERT into EMP (empno,ename) VALUES (2, ' Dan ');
Commit TRANSACTION;
At the same time, I found that if I did not commit in SQL Server, I would open a session and still see the changed data. But in Oracle, this is absolutely invisible, unless the data is submitted. DML operations in SQL Server are submitted automatically. As a result, transactions are sometimes used.
Database transaction (DB Transaction) is a series of actions performed as a single logical unit of work. Transaction processing ensures that data-oriented resources are not permanently updated unless all operations within the transactional unit are completed successfully. By combining a set of related actions into a unit that is either fully successful or all failed, you can simplify error recovery and make your application more reliable. To be a transaction, a logical unit of work must satisfy the so-called acid (atomicity, consistency, isolation, and durability) attribute.