使用存储过程
Create proc procname (参数列表)
as
begin
Begin Trans
Insert(Update) 数据库1.表1 ...
if @@rowcount = 0
goto aa
Insert(Update) 数据库2.表2 ...
if @@rowcount = 0
goto aa
Commit Trans
aa:
rollback Trans
end
Create proc procname (参数列表)
as
begin
Begin Trans
Insert(Update) 数据库1.表1 ...
if @@rowcount = 0
goto aa
Insert(Update) 数据库2.表2 ...
if @@rowcount = 0
goto aa
Commit Trans
aa:
rollback Trans
end
解决方案 »
- 下载了一个项目,但是没有数据库,帮我看看这个是不是创建数据库的脚本!
- database engine服务
- 各位高手帮帮忙!NTEXT类型的数据存储问题
- 请教inner join 与一般笛卡尔积的区别,如select * from tb1 a inner join tb2 b on a.id=b.id 与select * from tb1 a ,tb2 b where a.id
- 1求一sql语句,谢谢!急!
- MSSQL视图数据错位
- 请大家务必帮帮我这个Sqlserver菜鸟^_^,串内按数字大小排序问题
- 数据库的某张表被我误删除了
- asp怎么样调用存储过程中的聚合函数呀。
- 如何用SQL语句写Access数据库中的日期型字段?(急!!!!!!!!!11)
- 网络联通,ODBC联不通,WHY??
- 请问有人查询过ntext 类型的字段内容吗,该怎么查出其诶容呢??
update a set col1='343'
失败则回滚
由事务管理器负责
Create proc procname (参数列表)
as
begin
Begin Trans
Insert(Update) 数据库1.表1 ...
if @@rowcount = 0
goto aa
Insert(Update) 数据库2.表2 ...
if @@rowcount = 0
goto aa
Commit Trans
return --增加这句
aa:
rollback Trans
end
当 SET XACT_ABORT 为 ON 时,如果 Transact-SQL 语句产生运行时错误,整个事务将终止并回滚。示例
下例导致在含有其它 Transact-SQL 语句的事务中发生违反外键错误。在第一个语句集中产生错误,但其它语句均成功执行且事务成功提交。在第二个语句集中,SET XACT_ABORT 设置为 ON。这导致语句错误使批处理终止,并使事务回滚。 CREATE TABLE t1 (a int PRIMARY KEY)
CREATE TABLE t2 (a int REFERENCES t1(a))
GO
INSERT INTO t1 VALUES (1)
INSERT INTO t1 VALUES (3)
INSERT INTO t1 VALUES (4)
INSERT INTO t1 VALUES (6)
GO
SET XACT_ABORT OFF
GO
BEGIN TRAN
INSERT INTO t2 VALUES (1)
INSERT INTO t2 VALUES (2) /* Foreign key error */
INSERT INTO t2 VALUES (3)
COMMIT TRAN
GOSET XACT_ABORT ON
GOBEGIN TRAN
INSERT INTO t2 VALUES (4)
INSERT INTO t2 VALUES (5) /* Foreign key error */
INSERT INTO t2 VALUES (6)
COMMIT TRAN
GO/* Select shows only keys 1 and 3 added.
Key 2 insert failed and was rolled back, but
XACT_ABORT was OFF and rest of transaction
succeeded.
Key 5 insert error with XACT_ABORT ON caused
all of the second transaction to roll back. */SELECT *
FROM t2
GODROP TABLE t2
DROP TABLE t1
GO