--1.使用事務(wù)定義與提交命令在數(shù)據(jù)庫(kù)studentcourse中創(chuàng)建一個(gè)--“綜合表”(學(xué)號(hào),姓名,性別,民族),并為它插入3行數(shù)據(jù),觀察--提交之前和之后的瀏覽與回滾情況。create table zonghe(sno varchar(10) PRimary key,sname varchar(10),ssex char(2),sjg char(10))select @@TRANCOUNT as trancountgobegin transaction addzongheinsert into zonghe(sno,sname,ssex,sjg)values('Q0403','陳力','男','漢族')insert into zonghe(sno,sname,ssex,sjg)values('Q0401','高手','男','漢族')insert into zonghe(sno,sname,ssex,sjg)values('Q0402','劉備','男','漢族')goselect @@TRANCOUNT as tancountif @@ERROR<>0 rollback tran select @@TRANCOUNT as trancount go commit tran addzongfen2. 定義事務(wù),在學(xué)生選課數(shù)據(jù)庫(kù)studentcourse的學(xué)生選課數(shù)據(jù)表SC中,為所有成績(jī)高于50分的同學(xué)的成績(jī)?cè)黾?0分。begin transaction addfenshugoupdate SC set sc.成績(jī)=SC.成績(jī)+50 from SCwhere SC.成績(jī)>50commit transaction addzongfen3. 定義一個(gè)事務(wù),向?qū)W生選課數(shù)據(jù)表SC中插入一行數(shù)據(jù)(S0408 C01 46),然后刪除該行。執(zhí)行結(jié)果是此行沒(méi)有加入。要求在刪除命令前定義保存點(diǎn)MY,并使用ROLLBACK語(yǔ)句將操作滾回到保存點(diǎn),即刪除前的狀態(tài).觀察全局變量@@TRANCOUNT的值的變化。begin tranuse studentcourseinsert into SCvalues('S0408','C01',46)save tran MYdelete from SC where sc.學(xué)號(hào)='S0408'rollback tran mycommit tran
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注