筆記-Microsoft SQL Server 2008技術內幕:T-SQL語言基礎-09 事務和並發

來源:互聯網
上載者:User

標籤:

事務必須有四個屬性:原子性、一致性、隔離性、持久性,這四個屬性的首字母可以縮寫為ACID。

以下代碼定義了一個事務,插入新訂單資料:

-- Start a new transactionBEGIN TRAN;  -- Declare a variable  DECLARE @neworderid AS INT;  -- Insert a new order into the Sales.Orders table  INSERT INTO Sales.Orders      (custid, empid, orderdate, requireddate, shippeddate,        shipperid, freight, shipname, shipaddress, shipcity,       shippostalcode, shipcountry)    VALUES      (85, 5, ‘20090212‘, ‘20090301‘, ‘20090216‘,       3, 32.38, N‘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 AS neworderid;  -- Insert order lines for new order into Sales.OrderDetails  INSERT INTO Sales.OrderDetails      (orderid, productid, unitprice, qty, discount)    VALUES(@neworderid, 11, 14.00, 12, 0.000);  INSERT INTO Sales.OrderDetails      (orderid, productid, unitprice, qty, discount)    VALUES(@neworderid, 42, 9.80, 10, 0.000);  INSERT INTO Sales.OrderDetails      (orderid, productid, unitprice, qty, discount)    VALUES(@neworderid, 72, 34.80, 5, 0.000);-- Commit the transactionCOMMIT TRAN;

 

筆記-Microsoft SQL Server 2008技術內幕:T-SQL語言基礎-09 事務和並發

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.