A transaction must have four properties: atomicity, consistency, isolation, persistence, and the first letter of these four attributes can be abbreviated as acid.
The following code defines a transaction that inserts New Order data:
--Start a new transactionBEGIN TRAN; --Declare A variable DECLARE @neworderid as INT; --Insert A new order into the Sales.orders table INSERT intosales.orders (CustID, Empid, OrderDate, RequiredDate, ShippedDate, ShipperID, freight, ShipName, shipaddr ESS, ShipCity, Shippostalcode, ShipCountry)VALUES ( -,5,'20090212','20090301','20090216', 3,32.38N'Ship to 85-b'N'6789 rue de l"'Abbaye'N'Reims', N'10345'N'France'); --Save The New Order ID in a variable SET @neworderid = scope_identity(); --Return The New Order ID SELECT @neworderid asNeworderid; --Insert order lines for New order into Sales.orderdetails INSERT intosales.orderdetails (OrderID, ProductID, UnitPrice, qty, Discount)VALUES(@neworderid, One,14.00, A,0.000); INSERT intosales.orderdetails (OrderID, ProductID, UnitPrice, qty, Discount)VALUES(@neworderid, the,9.80,Ten,0.000); INSERT intosales.orderdetails (OrderID, ProductID, UnitPrice, qty, Discount)VALUES(@neworderid, the,34.80,5,0.000);--Commit The transactionCOMMIT TRAN;
Note-microsoft SQL Server 2008 Tech Insider: T-SQL Language Basics-09 Transactions and concurrency