最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SQL Server重溫 事務(wù)

 更新時(shí)間:2012年08月03日 16:50:22   作者:  
當(dāng)對(duì)多個(gè)表進(jìn)行更新的時(shí)候,某條執(zhí)行失敗。為了保持?jǐn)?shù)據(jù)的完整性,需要使用事務(wù)回滾
為什么使用事務(wù)
  當(dāng)對(duì)多個(gè)表進(jìn)行更新的時(shí)候,某條執(zhí)行失敗。為了保持?jǐn)?shù)據(jù)的完整性,需要使用事務(wù)回滾。
顯示設(shè)置事務(wù)
復(fù)制代碼 代碼如下:

begin try
begin transaction
insert into shiwu (asd) values ('aasdasda');
commit transaction
end try
begin catch
select ERROR_NUMBER() as errornumber
rollback transaction
end catch

隱式設(shè)置事務(wù)
復(fù)制代碼 代碼如下:

set implicit_transactions on; -- 啟動(dòng)隱式事務(wù)
go
begin try
insert into shiwu (asd) values ('aasdasda');
insert into shiwu (asd) values ('aasdasda');
commit transaction;
end try
begin catch
select ERROR_NUMBER() as errornumber
rollback transaction; --回滾事務(wù)
end catch
set implicit_transactions off; --關(guān)閉隱式事務(wù)
go

顯示事務(wù)以下語(yǔ)句不能使用,隱式事務(wù)可以
復(fù)制代碼 代碼如下:

alter database;
backup;
create database;
drop database;
reconfigure;
restore;
update statistics;

顯示事務(wù)可以嵌套使用
復(fù)制代碼 代碼如下:

--創(chuàng)建存儲(chǔ)過(guò)程
create procedure qiantaoProc
@asd nchar(10)
as
begin
begin try
begin transaction innerTrans
save transaction savepoint --創(chuàng)建事務(wù)保存點(diǎn)
insert into shiwu (asd) values (@asd);
commit transaction innerTrans
end try
begin catch
rollback transaction savepoint --回滾到保存點(diǎn)
commit transaction innerTrans
end catch
end
go
begin transaction outrans
exec qiantaoProc 'asdasd';
rollback transaction outrans

事務(wù)嵌套,回滾外層事務(wù)時(shí),如果嵌套內(nèi)的事務(wù)已經(jīng)回滾過(guò)則會(huì)有異常。此時(shí)需要使用事務(wù)保存點(diǎn)。如上代碼。

相關(guān)文章

最新評(píng)論

凌源市| 镇安县| 兰坪| 忻城县| 乡城县| 葵青区| 双鸭山市| 宜章县| 罗定市| 澜沧| 克什克腾旗| 正安县| 绥化市| 铁岭市| 大宁县| 游戏| 邳州市| 南陵县| 花垣县| 九龙城区| 伊金霍洛旗| 密山市| 城步| 库车县| 合川市| 蒲江县| 临颍县| 定襄县| 奉新县| 合川市| 五台县| 西畴县| 景洪市| 东台市| 靖州| 涟源市| 锦州市| 东丽区| 迭部县| 汝城县| 栖霞市|