SQL Server?е?????????
???????????? ???????[ 2014/6/10 13:15:00 ] ????????SQL ?????
??????????????
??????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????д??
????????????????????????????????????????????????????????????????????
????????????????????????????о?????????????????ú???????????????????????????????
???????????--????????
??????????????е??????????????£???????????????
?????????????
??????????????У???д??2??sql?????????????????????????????????-1 ?? ?????????????????????????????????????????????????????????????????????????????У???????????????????£????????
????????????????????????????????У??????????У?????????????
????????????????????????????????????????????
??????????????????????????????????????????У??????????С?
?????????????????????????е?????????????????
???????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????
?????????SQL Server?????????3??????????
???????????????SQL Server??????????????????Sql??????????????????д???????????м????????Update ???2????ε??????????1????ζ????????????????????
???????????T-sql????????Begin Transaction?????????????Commit Transaction ??????Rollback Transaction ????????????
??????????????Set IMPLICIT_TRANSACTIONS ON ?????????????????????Begin Transaction????????????????????????????????????????????????Commit Transaction ??????Rollback Transaction ????????ɡ?
???????????????
????????????????
????Begin Transaction????????????
????Commit Transaction??????????????У?????????????????
????Rollback Transaction?????????????г???????????д??????????????????????????????????
????Save Transaction?????????????????????????????????????????????????????????????????????
????????????????????????????????????????????
1 ---????????
2 begin tran
3 --??????????????????????????е?????????????
4 begin try
5 --??????
6 insert into lives (Eat??Play??Numb) values ('????'??'????'??1)
7 --Numb?int?????????
8 insert into lives (Eat??Play??Numb) values ('????'??'????'??'abc')
9 --??????
10 insert into lives (Eat??Play??Numb) values ('????'??'????'??2)
11 end try
12 begin catch
13 select Error_number() as ErrorNumber?? --???????
14 Error_severity() as ErrorSeverity?? --???????????????С??10 try catch ??????
15 Error_state() as ErrorState ?? --????????
16 Error_Procedure() as ErrorProcedure ?? --????????洢????????????????
17 Error_line() as ErrorLine?? --??????????к?
18 Error_message() as ErrorMessage --???????????
19 if(@@trancount>0) --??????@@trancount??????????+1?????????ж????п???????
20 rollback tran ---????????????????????????????????в???????
21 end catch
22 if(@@trancount>0)
23 commit tran --??????Lives???У???????3???????
24
25 --??????????ID ??Numb?int ??????????nvarchar????
26 select * from lives
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11