begin transaction
......
if @@error<> 0 goto QuitWithRollback.....
if @@error<>0 goto QuitWithRollback
commit transaction
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
......
if @@error<> 0 goto QuitWithRollback.....
if @@error<>0 goto QuitWithRollback
commit transaction
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
GO
1.直接通过RETURN @RC来判断,前台的APP可以通过RETURNCODE获得返回值。
SELECT @RC=@@ERROR
IF @RC<>0
BEGIN
SELECT @RC=-1000
RETURN @RC
END
2.通过RAISERROR(),将事件ERROR MESSAGE记录到SYSTEM EVENT VIEWER(EVENTID 最好大于50000)
IF (@@JOB_ID = 1) and (@@EMP_lVl <> 10)
BEGIN
RAISERROR ('Job id 1 expects the default level of 10.', 50001, 1)
ROLLBACK TRANSACTION
END
这样一来,程序就不用连接两个数据库了.
注意不是用import,而是程序中要调用的
??
不是很明白,最好详细一点!不过如果你要访问其它DATABASE,可以通过SP_ADDLINKEDSERVER来实现。
比如一边创建用户,另一边也要自动加上(结构并不完全相同).是两个sql的数据库.
我们只好建立不同的连接,两边做操作.
select * from server.database.dbo.tablename