sql server - How to use transactions (begin transaction, commit transaction)? -


I have seen the use of transactions in some cases, but in reality it never really understood which situations to be used needed. How and when transactions should be used (start transaction details)? I have read that Microsoft does not suggest using a transaction statement (committed, rollback) inside a trigger and stored procedure.

Transaction can be used with handling errors in stored procedures or SQL scripts, ensuring that To do everything that is consistent, insert or insert data.

For example, if you have a stored procedure that contains a record of a parent's table and a child's table, you want to ensure that the original record is included first; If this fails, you can rollback your changes so that you do not have records of an orphan child.

There are ways to use error handling in SQL Server in SQL Server Sommarskog.

Finally, where Microsoft has suggested transactions in stored procedures not ? I think it would be an ideal place to use stored procedures.


Comments