Transaction and Stored Procedure in SqlServer
Explain difference between Transaction and Stored Procedure ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Javeed M ShaikhPosted Oct 17, 2011, 2:01 PM
You use TRANSACTIONS when you want to explicitly COMMIT or ROLLBACK your activity whereas stored procedure does explicit commits and does not perform in a group unless specified. For example if following statement is in the stored procedure:
INSERT INTO TABLEA;
UPDATE TABLEB;
and if UPDATE fails than the INSERT into TABLEA will be commited in the database and if you wrap this thing in the TRANSACTION like below:
BEGIN TRANS
INSERT INTO TABLEA;
UPDATE TABLEB;
COMMIT;
It will rollback if line 2 UPDATE fails.
Please do not forget to mark "Accepted Answer".
Prabhu RajaPosted Oct 18, 2011, 6:18 AM
A transaction is a logical unit of work that contains one or more SQL statements.A transaction ends when it is committed or rolled back, either explicitly with a COMMIT or ROLLBACK statement or implicitly when a DDL statement is issued.
Stored procedures contains one or more SQL statements that are precomplied. This is simliar to functions or procedures in any programming languages.