Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Question

Author  Topic 

Laith Scofield
Starting Member

10 Posts

Posted - 2010-08-11 : 15:53:13
Hi guys
am a beginner with sql and i reading a book about sql for wrox
i got read something called "Sql transaction"
and i didn't catch it on
can you explain to me what does "Sql transaction" mean ???
and I'll be so grateful...

"It's fine to celebrate success but it is more important to heed the lessons of failure."
Bill Gates

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-08-11 : 17:29:28
The term "Transaction" can mean 2 things.

Any operation that modifies data can be termed a transaction.

More commonly however, we mean an ATOMic operation, or set of operations, that can be committed or rolled back.

One common example of a transaction occurs when you transfer funds from one bank account to another.

UPDATE Checking SET amount = amount - 100;
UPDATE Savings SET amount = amount + 100;

We need to be certain that if either statement fails (for whatever reason) that they BOTH fail. So we wrap it in a transaction...

BEGIN TRANSACTION
UPDATE Checking SET amount = amount - 100;
UPDATE Savings SET amount = amount + 100;

IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN 0
END
COMMIT
RETURN 1


For more info, please review these:
http://msdn.microsoft.com/en-us/library/ms188929.aspx
http://en.wikipedia.org/wiki/Database_transaction
Go to Top of Page

Laith Scofield
Starting Member

10 Posts

Posted - 2010-08-11 : 18:19:54
thanks dude..

"It's fine to celebrate success but it is more important to heed the lessons of failure."
Bill Gates
Go to Top of Page
   

- Advertisement -