



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、課程名稱數(shù)據(jù)庫(kù)技術(shù)實(shí)驗(yàn)實(shí)驗(yàn)名稱存儲(chǔ)過(guò)程和觸發(fā)器的使用成績(jī)學(xué)號(hào)姓名班級(jí)日期14.11.25實(shí)驗(yàn)?zāi)康模?. 掌握存儲(chǔ)過(guò)程的使用方法;2. 掌握觸發(fā)器的實(shí)現(xiàn)方法;實(shí)驗(yàn)平臺(tái):利用RDBMS( SQL Server 2008)及其交互查詢工具(查詢分析器)來(lái)操作T-SQL 語(yǔ)言;實(shí)驗(yàn)內(nèi)容:1. 存儲(chǔ)過(guò)程( 1) 創(chuàng)建存儲(chǔ)過(guò)程,要求當(dāng)一個(gè)員工的工作年份大于6 年時(shí)將其轉(zhuǎn)到經(jīng)理辦公室工作。alter procedure yuangong_infol EmployeeID char(6),name nchar(20)asbegindeclare year intset year=(select WorkYea
2、rfrom Employeeswhere EmployeeID =EmployeeID )declare DepartmentID char(3)set DepartmentID =(select DepartmentIDfrom Departmentswhere DepartmentName=name)if (year>6)update Employeesset DepartmentID =DepartmentIDwhere EmployeeID =EmployeeIDEndexec dbo.yuangong_infol '000000','經(jīng)理辦公室 '
3、;( 2) 創(chuàng)建存儲(chǔ)過(guò)程,根據(jù)每個(gè)員工的學(xué)歷將收入提高500 元。alter proc SA_IN enu char( 6)asbeginupdate Salaryset InCome =InCome+500from Salary,Employeeswhere Employees.EmployeeID =Salary.EmployeeID and Education=enu endselect InComefrom Salary,Employeeswhere Salary.EmployeeID =Employees.EmployeeID and Education='本科 '
4、goexec dbo.sa_in '本科 'goselect InComefrom Salary,Employeeswhere Salary.EmployeeID =Employees.EmployeeID and Education='本科 ' select InComefrom Salary,Employeeswhere Salary.EmployeeID =Employees.EmployeeID and Education='本科 '( 3) 創(chuàng)建存儲(chǔ)過(guò)程,使用游標(biāo)計(jì)算本科及以上學(xué)歷的員工在總員工數(shù)中的比例。declareeduvarch
5、ar( 10),part_countint,all_countint;declaremycursorcursorforselectdistincteducation,COUNT( education)over( partitionby education)aspart_count,COUNT( education)over()as all_countfromEmployeesopenmycursorfetchnextfrommycursorintoedu, part_count, all_countwhileFETCH_STATUS= 0 beginprintedu+ ' 占總?cè)藬?shù)比例
6、:' + convert( varchar( 100 ), convert( numeric ( 38 , 2 ), part_count/ 1.0 / all_count* 100 )+ '%'fetchnextfrommycursorintoedu, part_count, all_countendclosemycusordeallocatemycursor( 4) 使用命令方式修改及刪除一個(gè)存儲(chǔ)過(guò)程。ifexists(selectworkyearfromEmployeeswhereworkyear= 3 )dropprocedureworkyear2. 觸發(fā)器(
7、1) 對(duì)于 YGGL數(shù)據(jù)庫(kù),表 Employees 的 Employeeid 列與表 Salary 的Employeeid列應(yīng)滿足參照完整性規(guī)則,請(qǐng)用觸發(fā)器實(shí)現(xiàn)兩個(gè)表間的參照完整性。create trigger Salaryins0 on Salaryfor insert,updateasbeginif (select employeeid from inserted) not in( select EmployeeID from Employees)rollbackendcreate trigger Employeesupdate0 on dbo.Employeesfor updateasb
8、eginupdate Salaryset employeeid=( select employeeid from inserted)where employeeid =(select employeeid from deleted)endcreate trigger Employeesdelete0 on Employeesfor deleteasbegindelete from Salarywhere employeeid =(select employeeid from deleted)end( 2)當(dāng)修改表Employees 時(shí),若將Employees 表中員工的工作時(shí)間增加1年,則將收
9、入增加500 ,若增加2 年則增加1000 ,依次增加。若工作時(shí)間減少則無(wú)變化。createtriggerem_workyearon Employeesafterupdateasbegindeclarea int , b intseta=( selectworkyearfrominserted)setb=( selectworkyearfromdeleted)if ( a>b)updateSalarysetincome= income+( a- b)* 500whereenployeeidin(selectEmployeesIDfrom inserted)endupdateEmploye
10、essetworkyear= 12whereEmployeesID= '000001'( 3)創(chuàng)建 UPDATE觸發(fā)器,當(dāng)Salary表中 InCome 值增加 500時(shí), outCome值則增加 50 。createtriggersa_incomeonSalaryforupdate as beginif (selectincomefrominserted)-(selectincomefromdeleted)= 500 )updateSalarysetoutcome = outcome+ 50whereenployeeid=( selectenployeeidfrominser
11、ted)end selectincome, outcomefromSalarywhereenployeeid= '000001'( 5) 創(chuàng)建 INSTEAD OF 觸發(fā)器,實(shí)現(xiàn)向不可更新視圖插入數(shù)據(jù)。createviewa_viewasselectEmployees. EmployeesID , name , workyear , income, outcomefromEmployees , SalarywhereEmployees. EmployeesID= Salary. enployeeidgocreatetriggergxston a_viewinsteadof in
12、sertasbegindeclareEichar( 6),name char ( 10 ),wy tinyint, ic float, oc floatselectEi = EmployeesID, name=name , wy=workyear, ic = income, oc= outcomefrominsertedinsertintoEmployees( EmployeesID , name , workyear)values ( Ei , name, wy)insertintoSalaryvalues( Ei , ic , oc)endinsertintoa_viewvalues( '000011','小芳',3,2000 ,1500)select* froma_viewwhereEmployeesID= '000011'( 5)創(chuàng)建DDL 觸發(fā)器,當(dāng)刪除數(shù)據(jù)庫(kù)時(shí),提示“無(wú)法刪除”并回滾刪除操作。crea
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江省金麗衢十二校2025屆化學(xué)高二下期末檢測(cè)試題含解析
- 江西省宜春市豐城九中2025年化學(xué)高二下期末學(xué)業(yè)質(zhì)量監(jiān)測(cè)模擬試題含解析
- 暗能量模型檢驗(yàn)-洞察及研究
- 溶石藥物靶點(diǎn)篩選-洞察及研究
- 四川雙流棠湖中學(xué)2025屆高二下化學(xué)期末學(xué)業(yè)質(zhì)量監(jiān)測(cè)試題含解析
- 安徽省蕪湖市名校2025屆高一下化學(xué)期末教學(xué)質(zhì)量檢測(cè)模擬試題含解析
- 陶瓷裝飾材料性能提升-洞察闡釋
- 生境破碎化效應(yīng)評(píng)估-洞察及研究
- 社會(huì)支持網(wǎng)絡(luò)構(gòu)建策略-洞察闡釋
- 材料科學(xué)與綠色華新工藝研究-洞察闡釋
- 數(shù)字化賦能高校思政課建設(shè)的策略研究
- 整體施工勞務(wù)服務(wù)方案
- 2025年度地下綜合管廊代建合同模板
- 中藥材種植安全事故應(yīng)急預(yù)案
- 水泥攪拌樁施工項(xiàng)目進(jìn)度管理措施
- 國(guó)家開(kāi)放大學(xué)法學(xué)本科《商法》期末紙質(zhì)考試第四大題案例分析庫(kù)2025珍藏版
- 2024年山東省消防工程查驗(yàn)技能競(jìng)賽理論考試題庫(kù)-下(多選、判斷題)
- 人工智能賦能教師數(shù)字素養(yǎng)提升
- 換電站合同范例
- 【超星學(xué)習(xí)通】馬克思主義基本原理(南開(kāi)大學(xué))爾雅章節(jié)測(cè)試網(wǎng)課答案
- 安全生產(chǎn)標(biāo)準(zhǔn)化實(shí)施細(xì)則范例(3篇)
評(píng)論
0/150
提交評(píng)論