最新国产好看的视频,伊人天堂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)論

隆林| 宝应县| 澎湖县| 吴堡县| 温宿县| 读书| 苗栗市| 无锡市| 阳谷县| 沙田区| 桓台县| 元阳县| 绥棱县| 舞钢市| 宣汉县| 饶河县| 肥西县| 蒙山县| 东乡县| 监利县| 聊城市| 南木林县| 桓仁| 西乌| 教育| 黔西县| 永寿县| 长葛市| 故城县| 肥乡县| 茂名市| 海丰县| 巴彦县| 凤台县| 临夏市| 揭西县| 苗栗县| 平江县| 蒙自县| 余干县| 边坝县|