【发布时间】:2016-10-07 13:56:06
【问题描述】:
这是我的代码。如何避免错误发生任何查询自动回滚已存储。
insert into muser(UserKey, Email, UserPassword)
values(@Key, @Useremail, 'test')
set @UserId = SCOPE_IDENTITY()
set @Key = NEWID()
insert into mUserProfile(UserProfileKey, UserId, UserEmail)
values(@Key, @UserId, @Useremail)
exec SP_Store @Useremail, @ClientId,
【问题讨论】:
-
不太明白你在问什么。您只是在询问将您的代码放入事务中并回滚吗?检查:msdn.microsoft.com/en-gb/library/ms188929.aspx
-
旁注:您应该不为您的存储过程使用
sp_前缀。微软有reserved that prefix for its own use (see Naming Stored Procedures),你确实会在未来某个时候冒着名称冲突的风险。 It's also bad for your stored procedure performance。最好只是简单地避免sp_并使用其他东西作为前缀 - 或者根本不使用前缀!
标签: sql-server try-catch