begin tran
insert into t1 (clbm) values ('0')
insert into t2 (clbm) values ('0')
insert into t3 (clbm) values ('0')
insert into t4 (clbm) values ('0')
commit tran
insert into t1 (clbm) values ('0')
insert into t2 (clbm) values ('0')
insert into t3 (clbm) values ('0')
insert into t4 (clbm) values ('0')
commit tran
begin tran
insert into t1 (clbm) values ('0')
if @@error<>0 goto error
insert into t2 (clbm) values ('0')
if @@error<>0 goto error
insert into t3 (clbm) values ('0')
if @@error<>0 goto error
insert into t4 (clbm) values ('0')
if @@error<>0 goto error
commit tran
returnerror:
rollback tran
print '错了!'+@@error
返回受上一语句影响的行数。语法
@@ROWCOUNT返回类型
integer注释
任何不返回行的语句将这一变量设置为 0 ,如 IF 语句。示例
下面的示例执行 UPDATE 语句并用 @@ROWCOUNT 来检测是否有发生更改的行。UPDATE authors SET au_lname = 'Jones'
WHERE au_id = '999-888-7777'
IF @@ROWCOUNT = 0
print 'Warning: No rows were updated'
--添加新記錄到storage
insert into storage (clbm,kc,kcHK,yprl,kyl) values (@clbm,@cskc,0,0,@cskc)--添加新記錄到priceAsk
insert into PRICEASK (materialID,lastprice,prePrice,prcDate,lastTradeDate) values
(@clbm,'0','1000000002222222222222255555',getDate(),getDate())
commit tran以上的第二條語句確定是會出錯的,但是在執行時,第一條記錄就自動被添加到DB中,接著才出現了第二條語句的執行錯誤,請問怎麼回事啊?