How do you handle transactions in T-SQL?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sangeetha SRank #212 · 11.4K reputationPosted Jul 15, 2025, 2:17 AM EDT
In T-SQL, transactions are used to ensure that a series of operations are executed as a single unit of work. This means either all operations succeed (commit) or none of them take effect (rollback), preserving data integrity.
BEGIN TRANSACTION;
UPDATE Accounts SET Balance = Balance - 100 WHERE AccountId = 1;
UPDATE Accounts SET Balance = Balance + 100 WHERE AccountId = 2;
-- Commit if everything is successful
COMMIT;