




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)1、 運用存儲過程創建STUDENT、GRADE、COURSE表(要求實現完整性)。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)2、 運用存儲過程創建STUDENT、DEPARTMENT、DORM表(要求實現完整性)。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)3、 運用存儲過程對STUDENT、DEPARTMENT、DORM表插入一條符合完整性的記錄。(內容自己定義)按照要求編寫相應代碼,執行結果后,并刪除
2、對象:(以學號+題號做文件名提交:990101_1)4、 編寫帶參的存儲過程:實現刪除01課程數據庫原理的相關信息。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)5、 編寫帶參的存儲過程:實現刪除990101學生原野的相關信息。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)6、 編寫帶參的存儲過程:實現宿舍號從2101修改為3101。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)7、 編寫帶參的存儲過程:實現查詢宿舍號“2505”的相關信息。按照要求編寫相應
3、代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)8、 運用觸發器對GRADE實現插入記錄“980101,08,99”(相關信息自己定義)。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)9、 運用觸發器對STUDENT表中的SEX實現數據范圍檢查,若出錯,提示信息。按照要求編寫相應代碼,執行結果后,并刪除對象:(以學號+題號做文件名提交:990101_1)10、運用觸發器對STUDENT表的操作只能在工作時間:9-15,每周一到五,實現數據安全性控制。答案:1、 用存儲過程創建STUDENT、GRADE、COURSE表(要
4、求實現完整性)。 use student_datagoif exists (select name from sysobjectswhere name='cun' and type='P')drop procedure cungocreate procedure cunasbeginif not exists(select name from sysobjectswhere name='student' and type='U')begincreate table student(sno char(6)NOT null uniqu
5、e,sname char(8) not null,sex char(2),sage int,dno char(4),dormno char(5),constraint FK_DEP FOREIGN KEY (dno) references department(dno), constraint PK_student primary key(sno)insert into studentvalues('990101','原野','男',21,'1','2101');endif not exists(select na
6、me from sysobjectswhere name='grade' and type='U')begincreate table grade(sno char(6),cno char(2),score intconstraint pk_grade primary key (sno,cno);insert into gradevalues ('990101','01',85);endif not exists(select name from sysobjectswhere name='course' and
7、type='U')begincreate table course(cno char(2) NOT null unique,cname char(20) not null,cpno char(2),credit int,teacher char(8)constraint FK_CP foreign key (cpno) references dorm(cpno),constraint PK_COr primary key(cno)insert into coursevalues('01','數據庫原理','05',4,'王
8、凱');endendgocunselect *from student2、 運用存儲過程創建STUDENT、DEPARTMENT、DORM表(要求實現完整性)。3、 運用存儲過程對STUDENT、DEPARTMENT、DORM表插入一條符合完整性的記錄。(內容自己定義)use studentgoif exists (select name from sysobjectswhere name='cun' and type='P')drop procedure cungocreate procedure cunssno char(6),ssname char
9、(8),ssex char(2),ssage int,ddno char(4),ddorm char(5) ,dddno char(4),ddname char(8),hhead char(20),dddorno char(5),dddtel char(7)asbeginif not exists(select sno from student where sno=ssno)if exists (select dno from department where dno=ddno)If exists(select dormno from dorm where dormno=ddorm)inser
10、t into student (sno,sname,sex,sage,dno,dormno)values(ssno,ssname,ssex,ssage,ddno,ddorm)if not exists(select dno from department where dno=dddno)if not exists(select dname from department where dname=ddname)insert into departmentvalues(dddno,ddname,hhead)if not exists(select dormno from dorm where do
11、rmno=dddorno)if not exists(select tele from dorm where tele=dddtel)insert into dormvalues(dddorno,dddtel)endgouse studentgocun '990109','達到','男',19,'4','2404','5','地質','哈哈','6504','8306753'select *from studentselect *fro
12、m departmentselect *from studentselect *from dorm4、 編寫帶參的存儲過程:實現刪除01課程數據庫原理的相關信息。 if exists(select name from sysobjectswhere name='del_cname' and type='p')drop procedure del_cnamegocreate procedure del_cnamecname char(20)asbegindelete grade where cno =(select cno from course where cn
13、ame='數據庫原理') delete course where cname=cnameendgoselect * from courseselect * from gradeuse student_datagodel_cname '數據庫原理'godrop procedure del_cname5、 編寫帶參的存儲過程:實現刪除990101學生原野的相關信息。 use student_data /*打開數據庫*/goif exists(select name from sysobjectswhere name ='del_S'and type
14、='p')drop procedure del_Sgocreate procedure del_Sstu char(6)asbegindelete grade where sno=studelete student where sno=stuendgoselect * from gradeselect * from studentdel_S '990101'6、 編寫帶參的存儲過程:實現宿舍號從2101修改為3101。 use student_dataif exists (select name from sysobjectswhere name = '
15、adjust_roo' and type = 'P')drop procedure adjust_roogocreate procedure adjust_roodormnoo char(5) ,dormnoo1 char(5)asbeginupdate student set dormno=dormnoo1where dormno=dormnoodelete from dormwhere dormno=dormnooendgoadjust_roo '2101', '3101'goselect * from student7、 編寫帶參的
16、存儲過程:實現查詢宿舍號“2505”的相關信息。use studentgoif exists(select name from sysobjectswhere name='search_dorm' and type='p')drop procedure search_dormgocreate procedure search_dormdormno char(5)asbeginselect dorm.*, sno,sname from dorm,studentwhere student.dormno=dorm. dormnoand dormno=dormnoend
17、gouse studentexecsearch_dorm '2505'godrop procedure search_dorm8、 運用觸發器對GRADE實現插入記錄“980101,08,99”(相關信息自己定義)。 use student_dataif exists(select name from sysobjectswhere name ='SC'and type ='tr')drop trigger SCgocreate trigger SC on gradefor insertasdeclare Sno char(6)declare C
18、no char(2)declare msg1 char(100)declare msg2 char(100)declare msg3 char(100)declare Score intselect Sno= Sno from insertedselect msg1='沒有學生'if not exists(select * from studentwhere sno =Sno )beginprint msg1rollback transactionreturnendselect Cno=Cno from insertedselect msg2='沒有課程'if
19、not exists(select * from coursewhere cno =Cno )beginprint msg2rollback transactionreturnendselect Score=score from insertedselect msg3='成績不對'if (Score is not NULL and (Score<0 or Score>100) beginprint msg3rollback transactionendgoinsert into grade(sno,cno,score)values('990101',
20、'01',NULL)delete grade where sno='990101'9、 運用觸發器對STUDENT表中的SEX實現數據范圍檢查,若出錯,提示信息。 use student_dataif exists (select name from sysobjectswhere name='tr_ssex' and type='TR')drop trigger tr_ssexgocreate trigger tr_ssex on studentbefore update,insertasdeclare msg varchar(
21、100)declare vssex char(2)select msg='數據有誤,請檢查后,重新輸入!'select vssex=sex from insertedif (vssex<>'男'and vssex<>'女')beginprint msgrollback transactionendreturngoselect * from studentupdate student set sex='王'where sno='990101'update student set sex='女' where sno='990101'insert into student(sno,sname,sex)values('
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 山東華宇工學院《普通生物學動物部分》2023-2024學年第二學期期末試卷
- 山東華宇工學院《城市公交規劃與運營管理》2023-2024學年第二學期期末試卷
- 新星職業技術學院《燃燒學》2023-2024學年第二學期期末試卷
- 江西科技職業學院《磁性材料與器件》2023-2024學年第二學期期末試卷
- 南京交通職業技術學院《城市能源系統》2023-2024學年第二學期期末試卷
- 南通師范高等專科學校《遙感概論實驗》2023-2024學年第一學期期末試卷
- 山東省蘭陵縣重點達標名校2025屆中考模擬最后十套:化學試題(三)考前提分仿真卷含解析
- 公司計件工資勞動合同書
- 二零二五抖音發布協議書模板
- 二零二五版月子中心月嫂服務合同書
- 麻醉三基培訓課件
- 學生牛奶、糕點配送服務承諾及售后服務
- 垃圾分類引領綠色生活新潮流
- 排水箱涵研究報告
- 地域的永恒魅力教案
- 體制內年度工作總結
- 卡通風幼兒園餐前播報
- 2024-2025年上海中考英語真題及答案解析
- 中國聯通項目管理系統總體介紹
- 新版MACSV系統手冊
- 智慧養老服務平臺建設投標方案(技術方案)
評論
0/150
提交評論