Note-microsoft SQL Server 2008 Tech Insider: T-SQL Language Basics-09 Transactions and concurrency

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.