有错误sql命令的事务

SELECT [stuid]
      ,[stuno]
      ,[name]
      ,[sex]
      ,[age]
      ,[address]
      ,[telphone]
  FROM [UFMeta_001].[dbo].[Student]
GO


INSERT INTO student VALUES (101,'zhangsan','zhangsan',0,13,'zhangsan','zhangsan')

INSERT INTO student VALUES (102,'wangwu','zhangsan',0,13,'zhangsan','zhangsan')

INSERT INTO student VALUES (103,'lishi','zhangsan',0,13,'zhangsan','zhangsan')

INSERT INTO student VALUES (104,'maliu','zhangsan',0,13,'zhangsan','zhangsan')

 

创建外键引用表

 

CREATE TABLE score
(
         stuid [nvarchar](50) NOT NULL  REFERENCES student(stuid),
         score int
)

GO

set XACT_abort off
begin transaction ab
insert into score values('101',100)
insert into score values('105',100)--不符合外键约束,无法插入。
insert into score values('102',100)
insert into score values('103',100)
insert into score values('104',100)
commit transaction ab


select * from score

 

执行后:

stuid  score

101 100
102 100
103 100
104 100

有错误操作的事务,事务里面包含的sql命令完整执行的情况。(需要设置XACT_abort )

posted @ 2011-10-26 19:06  viola  阅读(190)  评论(0编辑  收藏  举报