begin tran
update a.....
update b.....
update c.....
update d.....
update e.....
update f.....
commit tran
update a.....
update b.....
update c.....
update d.....
update e.....
update f.....
commit tran
解决方案 »
- 求助!本地服务器的自动上传新的数据到远程服务器如何操作
- 急....动态行转列又出新问题啦?加了个合计,拜托各位帮帮忙,谢谢啦!
- 一个查询的问题
- 请问如何使用bcp?如何把一个表的数据导出为文本? 只有90分了!具体见内!谢谢!
- 急,无法为更新定位行集的问题~~请大家帮忙,谢谢!!!
- 三表联合操作疑问
- sql server 2012中的一个数据库日志文件坏了,如何还原数据库?
- 怎样使数据库反向生成该数据库的表关系
- 能否在触发器中得到当前这个触发器所在的表名(有些变态是不是?)
- sql连接服务器的问题,碰到好多次了,就是不知道为什么
- 再问,关于匹配整个单词的查询.
- ---如何访问局域网上的另一个sqlserver中数据库的一个表呢?请大家帮忙看看。---
gocreate table #Table1 (a tinyint)
go
begin tran
insert #table1 values(1) ----成功
insert #table1 values(1000) ----这句将报错
commit tran
go
select * from #table1
go
drop table #table1
create table #Table1 (a tinyint)
go
begin tran
insert #table1 values(1) ----成功
insert #table1 values(1000) ----这句将报错
commit tran
在1000报错之后,1仍然插了进去,我要求1也回滚,请帮帮忙!!!
指定当 Transact-SQL 语句产生运行时错误时,Microsoft® SQL Server™ 是否自动回滚当前事务。语法
SET XACT_ABORT { ON | OFF }注释
当 SET XACT_ABORT 为 ON 时,如果 Transact-SQL 语句产生运行时错误,整个事务将终止并回滚。为 OFF 时,只回滚产生错误的 Transact-SQL 语句,而事务将继续进行处理。编译错误(如语法错误)不受 SET XACT_ABORT 的影响。对于大多数 OLE DB 提供程序(包括 SQL Server),隐性或显式事务中的数据修改语句必须将 XACT_ABORT 设置为 ON。唯一不需要该选项的情况是提供程序支持嵌套事务时。有关更多信息,请参见分布式查询和分布式事务。 SET XACT_ABORT 的设置是在执行或运行时设置,而不是在分析时设置。示例
下例导致在含有其它 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
select * from #table1
看呀。
update a.....
if @@error<>0 goto error
update b.....
if @@error<>0 goto error
update c.....
if @@error<>0 goto error
update d.....
if @@error<>0 goto error
update e.....
if @@error<>0 goto error
update f.....
if @@error<>0 goto error
commit tran
returnerror:
rollback tran