




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、-. z.二、簡單的數(shù)據(jù)查詢此題中所用的數(shù)據(jù)庫是第1題中所建立的Study數(shù)據(jù)庫。(1)查詢所有同學(xué)的根本信息,包括:*s_no、班級(jí)號(hào)class_no、*s_name、性別S_se*、出生日期s_birthday。 (2)查詢所有同學(xué),要求顯示其*s_no、*s_name。 (3)查詢所有男同學(xué),要求顯示其*s_no、*s_name、出生日期s_birthday。 (4)查詢所有出生日期在1980一01一01前的女同學(xué),要求顯示其*s no、*S_name、性別s_se*、出生日期s_birthday。 (5)查詢所有姓李的男同學(xué),要求顯示其*s _no、*s _name、性別s _se*、
2、出生日期s _birthday。 (6)查詢所有*中含有一字的同學(xué),要求顯示其*s _no、*s_ name。 (7)查詢所有職稱不是講師的教師,要求顯示其教師號(hào)t _no、*t _name、職稱t _title。 (8)查詢雖選修了課程,但未參加考試的所有同學(xué),要求顯示出這些同學(xué)的*s _no。 (9)查詢所有考試不及格的同學(xué),要求顯示出這些同學(xué)的*s _no、成績score,并按成績降序排列。 (10)查詢出課程號(hào)為01001,02001,02003的所有課程,要求顯示出課程號(hào)course_no、Course_name。(要求用in運(yùn)算符)。三、復(fù)雜數(shù)據(jù)查詢此題中所用的數(shù)據(jù)庫是第l題中所建
3、立的Study數(shù)據(jù)庫。 (1)查詢所有同學(xué)的選課及成績情況,要求顯示學(xué)生的*s _no、*s_name、課程號(hào)Course_no和課程的成績score。 (2)查詢所有同學(xué)的選課及成績情況,要求顯示學(xué)生的*s _name、課程名稱course_name、課程的成績score,并將查詢結(jié)果存放到一個(gè)新的數(shù)據(jù)表new_table中。 (3)查詢計(jì)算機(jī)99-1班的同學(xué)的選課及成績情況,要求顯示學(xué)生的*s_ no、*s _name、課程號(hào)course _no、課程名稱course_name、課程的成績score。 (4)查詢所有同學(xué)的學(xué)分情況(假設(shè)課程成績=60時(shí)可獲得該門課程的學(xué)分),要求顯示學(xué)生的
4、*s _no、*s_ name、總學(xué)分(將該列定名為:total_score)。(用JOIN) (5)查詢所有同學(xué)的平均成績及選課門數(shù),要求顯示學(xué)生的*s_ no、*s_ name、平均成績(將該列定名為:average_score)、選課的門數(shù)(將該列定名為:choice_num)。 (6)查詢所有選修了課程但未參加考試的所有同學(xué)及相應(yīng)的課程,要求顯示學(xué)生的*S_ no、*s_ name、課程號(hào)course_no、課程名稱course_name。 (7)查詢所有選修了課程但考試不及格(假設(shè)60分為不及格)的所有同學(xué)及相應(yīng)的課程,要求顯示學(xué)生的*s_no、*s_name、課程號(hào)course_n
5、o、課程名稱course _name、課程成績course_score。 (8)查詢選修了課程名為程序設(shè)計(jì)語言的所有同學(xué)及成績情況,要求顯示學(xué)生的*s_ name、課程的成績score。(使用ANY) (9)查詢計(jì)算機(jī)系的所有同學(xué)及成績情況,要求顯示學(xué)生的*s_ no、*s _name、班級(jí)名稱class _name、課程號(hào)course _no、課程名稱course_name、課程的成績score。 (10)查詢所有教師的任課情況,要求顯示教師*t _name、擔(dān)任課程的名稱course _name。四、用Transact-SQL語句定義存儲(chǔ)過程1、創(chuàng)立一個(gè)能向?qū)W生表Student 中插入一條
6、記錄的存儲(chǔ)過程Insert_student,該過程需要5個(gè)參數(shù),分別用來傳遞*、*、班級(jí)、性別、出生日期。2、寫出執(zhí)行存儲(chǔ)過程Insert_student 的SQL 語句,向數(shù)據(jù)表Student 中插入一個(gè)新同學(xué),并提供相應(yīng)的實(shí)參值實(shí)參值自己給出。3、創(chuàng)立一個(gè)向課程表中插入一門新課程的存儲(chǔ)過程Insert_course,該存儲(chǔ)過程需要三個(gè)參數(shù),分別用來傳遞課程號(hào)、課程名、學(xué)分,但允許參數(shù)學(xué)分的默認(rèn)值為2,即當(dāng)執(zhí)行存儲(chǔ)過程Insert_course時(shí),未給參數(shù)學(xué)分提供實(shí)參值時(shí),存儲(chǔ)過程將按默認(rèn)值2進(jìn)展運(yùn)算。4、執(zhí)行存儲(chǔ)過程Insert_course,向課程表Course中插入一門新課程。分兩種情
7、況寫出相應(yīng)的SQL命令1提供三個(gè)實(shí)參值執(zhí)行存儲(chǔ)過程Insert_course三個(gè)參數(shù)值由用戶提供2只提供二個(gè)實(shí)參值執(zhí)行存儲(chǔ)過程Insert_course,即:不提供與參數(shù)學(xué)分對(duì)應(yīng)的實(shí)參值。5、創(chuàng)立一個(gè)名為Query_student的存儲(chǔ)過程,該存儲(chǔ)過程的功能是根據(jù)*查詢學(xué)生表中*一學(xué)生的*、年級(jí)、性別及出生日期。6、執(zhí)行存儲(chǔ)過程Query_student,查詢*為001101的學(xué)生的*、班級(jí)號(hào)、性別及出生日期。寫出完成此功能的SQL命令。五、用Transact-SQL語句自定義觸發(fā)器1、創(chuàng)立一個(gè)向?qū)W生表Student中插入一新同學(xué)時(shí)能自動(dòng)列出全部同學(xué)信息的觸發(fā)器Display_trigger2
8、、執(zhí)行存儲(chǔ)過程insert_student,向?qū)W生表中插入一新同學(xué),看觸發(fā)器Display_trigger是否被執(zhí)行2簡單的數(shù)據(jù)查詢(1)select*fromStudent;(2)selects_no,s_namefromStudent(3)selects_no,s_name,s_birthdayfromStudentwheres_se*=男(4)Selects_no,s_name,s_se*,s_birthdayFromStudentWhere (s_se*=女)and(s_birthday=1980-01-01)(5) selects_no,s_name,s_se*,s_birthday
9、fromStudentWheres_se*=男ands_namelike李%(6) selects_no,s_nameFromstudentWheres_namelike%一%(7) selectt_no,t_name,t_titlefromTeacherwheret_titlenotin(講師)(8) selects_nofromChoicewherescoreisnull(9) selects_no,scorefromChoicewherescore=2(14) selectavg(score)as平均成績,ma*(score)as最高分,min(score)as最低分fromChoice
10、wherecourse_no=01001(15) selectt_name,t_birthdayfromTeacherwhere (t_birthday1960)and(t_title=講師)orderbyt_birthdaydesc3.復(fù)雜的數(shù)據(jù)查詢1selectstudent.s_no,s_name,course_no,scorefromStudentleftouterjoinChoiceonStudent.s_no=Choice.s_no2selects_name,Course.course_name,scoreintonew_tablefromStudent,Choice,Course
11、whereCourse.course_no=Choice.course_noandStudent.s_no=Choice.s_no3selectStudent.s_no,s_name,Choice.course_no,course_name,scorefromclass,Student,Choice,Coursewhereclass_name=計(jì)算機(jī)99-1andChoice.course_no=Course.course_noandChoice.s_no=Student.s_no4selectStudent.s_no,s_name,sum(course_score)astotal_score
12、FromStudentInnerjoinChoiceonStudent.s_no=Choice.s_noInnerjoinCourseonChoice.course_no=Course.course_noandscore=60 groupbyStudent.s_no,s_name5selectc.s_no,s.s_name,avg(c.score)average_score,count(*)choice_numfromChoicec,Studentswherec.s_no=s.s_nogroupbyc.s_no,s.s_name;(6) selects.s_no,s.s_name,co.cou
13、rse_no,co.course_namefromChoicec,Students,Coursecowherec.score=0 andc.s_no=s.s_noandco.course_no=c.course_no;(7) selectst.s_no,st.s_name,co.course_no,co.course_name,co.course_scorefromChoicec,Courseco,Studentstwherec.score=2(14) selectavg(score)as平均成績,ma*(score)as最高分,min(score)as最低分fromChoicewhereco
14、urse_no=01001(15) selectt_name,t_birthdayfromTeacherwhere (t_birthday1960)and(t_title=講師)orderbyt_birthdaydesc3.復(fù)雜的數(shù)據(jù)查詢1selectstudent.s_no,s_name,course_no,scorefromStudentleftouterjoinChoiceonStudent.s_no=Choice.s_no2selects_name,Course.course_name,scoreintonew_tablefromStudent,Choice,CoursewhereCo
15、urse.course_no=Choice.course_noandStudent.s_no=Choice.s_no3selectStudent.s_no,s_name,Choice.course_no,course_name,scorefromclass,Student,Choice,Coursewhereclass_name=計(jì)算機(jī)99-1andChoice.course_no=Course.course_noandChoice.s_no=Student.s_no4selectStudent.s_no,s_name,sum(course_score)astotal_scoreFromStu
16、dentInnerjoinChoiceonStudent.s_no=Choice.s_noInnerjoinCourseonChoice.course_no=Course.course_noandscore=60 groupbyStudent.s_no,s_name5selectc.s_no,s.s_name,avg(c.score)average_score,count(*)choice_numfromChoicec,Studentswherec.s_no=s.s_nogroupbyc.s_no,s.s_name;(6) selects.s_no,s.s_name,co.course_no,
17、co.course_namefromChoicec,Students,Coursecowherec.score=0 andc.s_no=s.s_noandco.course_no=c.course_no;(7) selectst.s_no,st.s_name,co.course_no,co.course_name,co.course_scorefromChoicec,Courseco,Studentstwherec.score60 andc.s_no=st.s_noandco.course_no=c.course_no;(8) selectst.s_name,c.scorefromChoice
18、c,Courseco,Studentstwherest.s_no=c.s_noandco.course_no=c.course_noandco.course_name=程序設(shè)計(jì)語言;selectst.s_no,st.s_name,c.class_name,co.course_no,co.course_name,ch.scorefromStudentst,Classc,Choicech,CoursecoWherec.class_no=st.class_noandc.class_dept=計(jì)算機(jī)系andch.s_no=st.s_noandco.course_no=ch.course_no;(10)
19、 selectte.t_name,co.course_namefromTeachingt,Teacherte,Coursecowheret.t_no=te.t_noandco.course_no=t.couse_no;(11)selectt.t_no,te.t_name,count(*)course_numberfromTeachingt,Teachertewheret.t_no=te.t_nogroupbyt.t_no,te.t_name;(12)select*fromStudentstwherest.class_noin(selectclass_nofromStudentwheres_na
20、me=李建國)(13)select*fromChoicech,StudentstwherenotE*ists(selectcourse_nofromCoursewherecourse_name=計(jì)算機(jī)根底andch.course_no!=course_no)andst.s_no=ch.s_no;(14)selectTeacher.t_namefromTeacher,Teaching,CoursewhereTeacher.t_no=Teaching.t_noandCourse.course_no=Teaching.Couse_noand(Course.course_name=數(shù)據(jù)庫原理與應(yīng)用)g
21、roupbyTeacher.t_nameunion(selectTeacher.t_namefromTeacher,Teaching,CoursewhereTeacher.t_no=Teaching.t_noandCourse.course_no=Teaching.Couse_noandCourse.course_name=數(shù)據(jù)構(gòu)造);(15)selectt.t_namefromTeachert,(selectte.t_no,count(*)cfromTeachingtegroupbyte.t_no)ccwherecc.c=6 andcc.t_no=t.t_no;4.用Transact-SQL語句定義存儲(chǔ)過程(1)createprocedureinsert_student(s_nochar(6),s_namechar(6),class_nochar(6),s_se*char(2),s_birthdaydatetime)asinsertintoStudent(s_no,s_name,class_no,s_se*,s_birthday)VALUES(s_no,s_name,class_no,s_se*,s_
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 5-Formylfuran-2-yl-methyl-acetate-13C6-Acetic-Acid-5-Formylfurfuryl-Ester-sup-13-sup-C-sub-6-sub-生命科學(xué)試劑-MCE
- 2025教育機(jī)構(gòu)品牌授權(quán)與課程體系全面轉(zhuǎn)讓合同范本
- 2025年度跨境貨運(yùn)安全責(zé)任合同(國際快遞)
- 2025年專業(yè)展會(huì)設(shè)施租賃與綜合運(yùn)營管理服務(wù)協(xié)議
- 2025年度海外留學(xué)子女教育權(quán)益分割協(xié)議模板
- 2025年綠色節(jié)能型住宅供暖系統(tǒng)設(shè)計(jì)及安裝工程合同
- 2025年醫(yī)藥研發(fā)機(jī)構(gòu)臨床試驗(yàn)執(zhí)行人員勞動(dòng)合同模板
- 2025年社區(qū)醫(yī)療機(jī)構(gòu)急診科業(yè)務(wù)外包合作協(xié)議
- 2025年智能健康管理APP用戶健康數(shù)據(jù)保密服務(wù)協(xié)議
- 2025年新能源電動(dòng)汽車租賃協(xié)議保證金與使用規(guī)定
- 2024城市電纜線路巖土工程勘察規(guī)范
- 變電站巡檢維護(hù)服務(wù)方案
- 華為質(zhì)量回溯(根因分析與糾正預(yù)防措施)模板
- GB/T 23781-2024黑芝麻糊質(zhì)量通則
- 2023版評(píng)審準(zhǔn)則和CNAS對(duì)照表
- 收養(yǎng)申請(qǐng)人情況聲明
- CATIA CAA 二次開發(fā)詳細(xì)教程(11) 程序的發(fā)布
- 分布式光伏發(fā)電項(xiàng)目可行性分析報(bào)告(方案)講解演示模板ppt課件-圖文
- 高空作業(yè)安全刷漆施工方案
- 醫(yī)療康養(yǎng)項(xiàng)目運(yùn)營方案
- 保密檔案培訓(xùn)課件
評(píng)論
0/150
提交評(píng)論