码迷,mamicode.com
首页 > 数据库 > 详细

笔记-Microsoft SQL Server 2008技术内幕:T-SQL语言基础-09 事务和并发

时间:2015-06-24 07:03:59      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

事务必须有四个属性:原子性、一致性、隔离性、持久性,这四个属性的首字母可以缩写为ACID。

以下代码定义了一个事务,插入新订单数据:

-- Start a new transaction
BEGIN 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, NShip to 85-B, N6789 rue de l‘‘Abbaye, NReims,
       N10345, NFrance);

  -- 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 transaction
COMMIT TRAN;

 

笔记-Microsoft SQL Server 2008技术内幕:T-SQL语言基础-09 事务和并发

标签:

原文地址:http://www.cnblogs.com/laixiancai/p/4596482.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!