版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、本文格式為word版,下載可任意編輯數(shù)據(jù)庫(kù)系統(tǒng)實(shí)驗(yàn)報(bào)告 數(shù)據(jù) 庫(kù)系統(tǒng) 試驗(yàn) 班 班 級(jí) 姓 姓 名 學(xué) 學(xué) 號(hào) 任課老師 計(jì)算機(jī)學(xué)院 本 試驗(yàn)一:基本 sql 語(yǔ)言 1. 試驗(yàn)?zāi)繕?biāo) 1.1. 嫻熟把握基本的 sql 語(yǔ)言。能夠利用 sql 定義語(yǔ)言(ddl)創(chuàng)建、刪除和修改數(shù)據(jù)庫(kù)的基本對(duì)象(表、視圖、約束和索引等),利用 sql 查詢語(yǔ)言(select)對(duì)數(shù)據(jù)中數(shù)據(jù)進(jìn)行檢索,利用 sql 修改語(yǔ)言(insert、update、delete)對(duì)數(shù)據(jù)中數(shù)據(jù)進(jìn)行插入、修改和刪除操作。能夠利用 sql 掌握語(yǔ)言(dcl)將數(shù)據(jù)庫(kù)的基本對(duì)象(表和視圖等)的各種權(quán)限授予其它用戶。 1.2. 熟識(shí) sql
2、server 2021 的交互式 sql 語(yǔ)言的操作環(huán)境。能夠利用 查詢分析器進(jìn)行 sql 語(yǔ)言的編輯和提交。 2. 試驗(yàn)要求 2.1. 寫出以下各個(gè)試驗(yàn)的 sql 語(yǔ)句。 2.2. 在 sql server 2021 的 查詢分析器環(huán)境中執(zhí)行 sql 語(yǔ)句,寫出每次執(zhí)行的結(jié)果。 2.3. 對(duì)于錯(cuò)誤的執(zhí)行結(jié)果,分析產(chǎn)生錯(cuò)誤的緣由,并寫出訂正錯(cuò)誤的方案。 2.4. sql 語(yǔ)句的書寫規(guī)范,要求每個(gè)查詢子句獨(dú)占一行,如: select sno, sname from s where sage=20 ; 留意:每次試驗(yàn)之后請(qǐng)作好 數(shù)據(jù)庫(kù) 備份。 下次試驗(yàn)之前進(jìn)行數(shù)據(jù)庫(kù)恢復(fù)。 3. 試驗(yàn)課時(shí) 本次試驗(yàn)
3、共計(jì) 10 課時(shí)。 4. 試驗(yàn)數(shù)據(jù) 本次試驗(yàn)中用到 6 個(gè)關(guān)系表(當(dāng)前用戶):course(課程)、dept(系)、s(同學(xué))、prof(老師)、pc(授課)、sc(選修)。 4.1. 關(guān)系模式。 snossnamesexagedno cno coursecname pcnocredit pno prof pname sal age dno dno dept dname dean snocnosc scorepnocnopc 4.2. 6 個(gè)關(guān)系表的定義。 course (課程) dept (系) s (學(xué) 生) 字段 名稱 類型 說(shuō)明 sno 同學(xué)號(hào) varchar(10) pk,not n
4、ull sname 同學(xué)名 varchar(10) not null sex 性別 varchar(10) 0,女;1,男 字段 名稱 類型 說(shuō)明 cno 課程號(hào) varchar(10) pk,not null cname 課程名 varchar(10) not null pcno 先修課程號(hào) varchar(10) credit 學(xué)分 real 字段 名稱 類型 說(shuō)明 dno 系號(hào) varchar(10) pk,not null dname 系名 varchar(10) not null dean 系主任號(hào) varchar(10) 系主任作為老師的編號(hào) age 年齡 real dno 所在系
5、號(hào) varchar(10) fk prof (老師) 字段 名稱 類型 說(shuō)明 pno 老師號(hào) varchar(10) pk,not null pname 老師名 varchar(10) not null sal 工資額 float age 年齡 real dno 所在系號(hào) varchar(10) fk sc (選修) 字段 名稱 類型 說(shuō)明 sno 同學(xué)號(hào) varchar(10) pk, not null fk cno 課程號(hào) varchar(10) fk score 成果 real pc (授課) 字段 名稱 類型 說(shuō)明 pno 同學(xué)號(hào) varchar(10) pk, not null fk
6、 cno 課程號(hào) varchar(10) fk 4.3. 6 個(gè)關(guān)系表的元組數(shù)據(jù)。 course (課程) cno cname pcno credit c1 數(shù)據(jù)庫(kù) c5 4 c2 離散數(shù)學(xué) c7 2 c3 組合數(shù)學(xué) c2 2 c4 操作系統(tǒng) c9 4 c5 數(shù)據(jù)結(jié)構(gòu) c2 3 c6 近世代數(shù) c7 2 c7 高等數(shù)學(xué) 4 c8 c 語(yǔ)言 c2 2 c9 數(shù)理規(guī)律 4 dept (系) dno dname dean d1 計(jì)算機(jī) p01 d2 數(shù)學(xué) p04 d3 物理 p07 s (同學(xué)) sno sname sex age dno s1 宋江 1 59 d1 s2 吳用 1 48 d1 s3
7、 魯智深 1 42 d1 s4 孫二娘 0 40 d2 s5 林沖 1 51 d2 s6 李逵 1 46 d2 s7 武松 1 36 d3 s8 扈三娘 0 30 d3 prof (老師) pno pname sal age dno p1 劉備 1800 59 d1 p2 諸葛亮 1600 48 d1 p3 關(guān)羽 1400 d1 p4 曹操 2200 40 d2 p5 司馬懿 2021 61 d2 p6 張遼 1700 46 d2 p7 孫權(quán) 2100 66 d3 p8 周瑜 1900 30 d3 p9 魯肅 1500 50 d3 sc (選修) sno cno score s1 c1 80
8、s1 c2 60 s1 c3 40 s1 c4 90 s1 c5 70 s1 c6 60 s1 c7 50 s1 c8 70 s1 c9 80 s2 c1 80 s2 c2 60 s2 c3 40 s2 c4 90 s3 c5 70 s3 c6 60 s4 c1 70 s4 c2 60 s4 c3 55 s4 c4 85 s4 c5 70 s4 c6 70 s4 c7 80 s4 c8 40 s4 c9 70 s5 c3 40 s5 c4 90 s5 c5 70 s5 c6 60 s5 c7 50 s6 c1 80 s6 c2 60 s6 c3 40 s6 c4 90 s7 c1 30 s7
9、c2 80 s7 c3 40 s7 c4 70 s7 c5 80 s7 c6 60 s7 c7 90 s7 c8 50 s7 c9 80 s8 c2 60 s8 c3 55 s8 c4 85 pc (授課) pno cno p1 c1 p2 c2 p3 c3 p4 c4 p5 c5 p6 c6 p7 c7 p8 c8 p9 c9 5. 試驗(yàn)步驟 5.1. sql server 2021 數(shù)據(jù)庫(kù)的安裝 、 啟動(dòng) 和創(chuàng)建新的數(shù)據(jù)庫(kù)。 。 sql server 2021 已安裝在本機(jī),一般采納的是 windows 認(rèn)證方式。因此當(dāng)你以默認(rèn) windows 用戶 administrator 登陸進(jìn)wi
10、ndow 操作系統(tǒng)之后,你就可以直接通過(guò) 服務(wù)管理器啟動(dòng) sql server 2021。 啟動(dòng)勝利之后的狀態(tài)如下(啟動(dòng)勝利之后,可以關(guān)閉 服務(wù)管理器): 之后可以通過(guò)打開(kāi)查詢分析器登陸到 sql server 2021,建立和 dbms 的會(huì)話。 windows 的系統(tǒng)管理員默認(rèn)對(duì)應(yīng) sql server 的系統(tǒng)管理員用戶sa。因此, 當(dāng)你以 windows 的系統(tǒng)管理員身份登陸到 sql server 之后,你在 sql server 中對(duì)應(yīng)的用戶名就是 sa。你可以對(duì) sql server 執(zhí)行利用此 windows默認(rèn)用戶身份登錄 sql server 任何操作了(當(dāng)然你也可以創(chuàng)建一個(gè)
11、新的用戶,該用戶最好在 windows 和sql server 中以相同的名字同時(shí)創(chuàng)建)。 利用 企 業(yè)管理器創(chuàng)建新的數(shù)據(jù)庫(kù) test。test 數(shù)據(jù)庫(kù)作為本次試驗(yàn)用數(shù)據(jù)庫(kù),在 test 數(shù)據(jù)庫(kù)中創(chuàng)建本次試驗(yàn)的全部數(shù)據(jù)庫(kù)對(duì)象。 5.2. create 語(yǔ)句 利用 create 語(yǔ)句創(chuàng)建以上 6 個(gè)關(guān)系表。同時(shí)利用 insert 語(yǔ)句將試驗(yàn)數(shù)據(jù)插入到相應(yīng)的表中。 1) 創(chuàng)建 course(課程)的 create 語(yǔ)句。 表的創(chuàng)建 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: create table course( cno varchar(10) primary key not null, cname
12、varchar(10) not null, pcno varchar(10), creatit real) 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into course(cno,cname,pcno,creatit) values("c1"," 數(shù)據(jù)庫(kù)","c5",4) insert into course(cno,cname,pcno,creatit) values("c2"," 離散數(shù)學(xué)","c7",2) insert into course
13、(cno,cname,pcno,creatit) values("c3"," 組合數(shù)學(xué)","c2",2) insert into course(cno,cname,pcno,creatit) values("c4"," 操作系統(tǒng)","c9",4) insert into course(cno,cname,pcno,creatit) values("c5"," 數(shù)據(jù)結(jié)構(gòu)","c2",3) insert into cou
14、rse(cno,cname,pcno,creatit) values("c6"," 近世代數(shù)","c7",2) insert into course(cno,cname,pcno,creatit) values("c7"," 高等數(shù)學(xué)",null,4) insert into course(cno,cname,pcno,creatit) values("c8","c 語(yǔ)言","c2",2) insert into course(cno,
15、cname,pcno,creatit) values("c9"," 數(shù)理規(guī)律",null,4) insert into course(cno,cname,pcno,creatit) values("c1"," 數(shù)據(jù)庫(kù)","c5",4) 型 中,字符型 varchar 類型的要用單引號(hào),數(shù)字型的 real ,float 類型的不用加單引號(hào),上面的4 應(yīng)改為 4 insert into course(cno,cname,pcno,creatit) values("c9",&quo
16、t; 數(shù)理規(guī)律",4) values 值中若為空,應(yīng)寫為 null ,不是用兩個(gè)單引號(hào) 表示 2) 創(chuàng)建 dept(系)的 create 語(yǔ)句。 表的創(chuàng)建 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: create table dept( dno varchar(10) primary key not null, dname varchar(10) not null, dean varchar(10) 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into dept(dno,dname,dean) values("d1"," 計(jì)算機(jī)&quo
17、t;,"p01") insert into dept(dno,dname,dean) values("d2"," 數(shù)學(xué)","p04") insert into dept(dno,dname,dean) values("d3"," 物理","p07") 3) 創(chuàng)建 s(同學(xué))的 create 語(yǔ)句。 表的創(chuàng)建 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: create table s( sno varchar(10) primary key not null, sn
18、ame varchar(10) not null, sex varchar(10) check(sex=0 or sex=1), age real , dno varchar(10) foreign key references dept(dno) not null) 為 有 外 鍵 約 束 時(shí) 格 式 為 dno varchar(10) foreign key references dept(dno) not null 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into s(sno,sname,sex,age,dno) values("s1",&
19、quot; 宋江","1",59,"d1") insert into s(sno,sname,sex,age,dno) values("s2"," 吳用","1",48,"d1") insert into s(sno,sname,sex,age,dno) values("s3"," 魯智深","1",42,"d1") insert into s(sno,sname,sex,age,dno
20、) values("s4"," 孫二娘","0",40,"d2") insert into s(sno,sname,sex,age,dno) values("s5"," 林沖","1",51,"d2") insert into s(sno,sname,sex,age,dno) values("s6"," 李逵","1",46,"d2") insert int
21、o s(sno,sname,sex,age,dno) values("s7"," 武松","1",36,"d3") insert into s(sno,sname,sex,age,dno) values("s8"," 扈三娘","0",30,"d3") 4) 創(chuàng)建 prof(老師)的 create 語(yǔ)句。 表的創(chuàng)建 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: create table prof( pno varchar(10) primary
22、 key not null, pname varchar(10) not null, sal float, age real, dno varchar(10) foreign key references dept(dno) not null) insert into prof(pno,pname,sal,age,dno) values("p1"," 劉備",1800,59,"d1") insert into prof(pno,pname,sal,age,dno) values("p2"," 諸葛亮&qu
23、ot;,1600,48,"d1") insert into prof(pno,pname,sal,age,dno) values("p3"," 關(guān)羽",1400,null,"d1") insert into prof(pno,pname,sal,age,dno) values("p4"," 曹操",2200,40,"d2") insert into prof(pno,pname,sal,age,dno) values("p5",&quo
24、t; 司馬懿",2021,61,"d2") insert into prof(pno,pname,sal,age,dno) values("p6"," 張遼",1700,46,"d2") insert into prof(pno,pname,sal,age,dno) values("p7"," 孫權(quán)",2100,66,"d3") insert into prof(pno,pname,sal,age,dno) values("p8&quo
25、t;," 周瑜",1900,30,"d3") insert into prof(pno,pname,sal,age,dno) values("p9"," 魯肅",1500,50,"d3") 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into prof(pno,pname,sal,age,dno) values("p1"," 劉備",1800,59,"d1") insert into prof(pno,pname
26、,sal,age,dno) values("p2"," 諸葛亮",1600,48,"d1") insert into prof(pno,pname,sal,age,dno) values("p3"," 關(guān)羽",1400,null,"d1") insert into prof(pno,pname,sal,age,dno) values("p4"," 曹操",2200,40,"d2") insert into prof(
27、pno,pname,sal,age,dno) values("p5"," 司馬懿",2021,61,"d2") insert into prof(pno,pname,sal,age,dno) values("p6"," 張遼",1700,46,"d2") insert into prof(pno,pname,sal,age,dno) values("p7"," 孫權(quán)",2100,66,"d3") insert int
28、o prof(pno,pname,sal,age,dno) values("p8"," 周瑜",1900,30,"d3") insert into prof(pno,pname,sal,age,dno) values("p9"," 魯肅",1500,50,"d3") 5) 創(chuàng)建 sc(選修)的 create 語(yǔ)句。 create table sc( sno varchar(10) foreign key references s(sno) not null, cno varc
29、har(10) foreign key references course(cno) not null, score real, primary key(sno,cno) 有多個(gè)字段的約束必需定義為表的約束形式 當(dāng) 當(dāng) sno,cno 都是主鍵時(shí)格式應(yīng)為: primary key(sno,cno) 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into sc(sno,cno,score) values ("s1","c1",80) insert into sc(sno,cno,score) values ("s1"
30、;,"c2",60) insert into sc(sno,cno,score) values ("s1","c3",40) insert into sc(sno,cno,score) values ("s1","c4",90) insert into sc(sno,cno,score) values ("s1","c5",70) insert into sc(sno,cno,score) values ("s1","c6&q
31、uot;,60) insert into sc(sno,cno,score) values ("s1","c7",50) insert into sc(sno,cno,score) values ("s1","c8",70) insert into sc(sno,cno,score) values ("s1","c9",80) insert into sc(sno,cno,score) values ("s2","c1",80) ins
32、ert into sc(sno,cno,score) values ("s2","c2",60) insert into sc(sno,cno,score) values ("s2","c3",40) insert into sc(sno,cno,score) values ("s2","c4",90) insert into sc(sno,cno,score) values ("s3","c5",70) insert into sc(
33、sno,cno,score) values ("s3","c6",60) insert into sc(sno,cno,score) values ("s4","c1",70) insert into sc(sno,cno,score) values ("s4","c2",60) insert into sc(sno,cno,score) values ("s4","c3",55) insert into sc(sno,cno,scor
34、e) values ("s4","c4",85) insert into sc(sno,cno,score) values ("s4","c5",70) insert into sc(sno,cno,score) values ("s4","c6",70) insert into sc(sno,cno,score) values ("s4","c7",80) insert into sc(sno,cno,score) values (&
35、quot;s4","c8",40) insert into sc(sno,cno,score) values ("s4","c9",70) insert into sc(sno,cno,score) values ("s5","c3",40) insert into sc(sno,cno,score) values ("s5","c4",90) insert into sc(sno,cno,score) values ("s5"
36、;,"c5",70) insert into sc(sno,cno,score) values ("s5","c6",60) insert into sc(sno,cno,score) values ("s5","c7",50) insert into sc(sno,cno,score) values ("s6","c1",80) insert into sc(sno,cno,score) values ("s6","c2&q
37、uot;,60) insert into sc(sno,cno,score) values ("s6","c3",40) insert into sc(sno,cno,score) values ("s6","c4",90) insert into sc(sno,cno,score) values ("s7","c1",30) insert into sc(sno,cno,score) values ("s7","c2",80) ins
38、ert into sc(sno,cno,score) values ("s7","c3",40) insert into sc(sno,cno,score) values ("s7","c4",70) insert into sc(sno,cno,score) values ("s7","c5",80) insert into sc(sno,cno,score) values ("s7","c6",60) insert into sc(
39、sno,cno,score) values ("s7","c7",90) insert into sc(sno,cno,score) values ("s7","c8",50) insert into sc(sno,cno,score) values ("s7","c9",80) insert into sc(sno,cno,score) values ("s8","c2",60) insert into sc(sno,cno,scor
40、e) values ("s8","c3",55) insert into sc(sno,cno,score) values ("s8","c4",85) 6) 創(chuàng)建 pc(授課)的 create 語(yǔ)句。 表的創(chuàng)建 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: create table pc( pno varchar(10) foreign key references prof(pno) not null, cno varchar(10) foreign key references course(cno) not nul
41、l) 向表插入數(shù)據(jù)的 sql 語(yǔ)句、消失的主要錯(cuò)誤及緣由: insert into pc(pno,cno) values("p1","c1") insert into pc(pno,cno) values("p2","c2") insert into pc(pno,cno) values("p3","c3") insert into pc(pno,cno) values("p4","c4") insert into pc(pno,cno
42、) values("p5","c5") insert into pc(pno,cno) values("p6","c6") insert into pc(pno,cno) values("p7","c7") insert into pc(pno,cno) values("p8","c8") insert into pc(pno,cno) values("p9","c9")*/ 5.3. selec
43、t 語(yǔ)句 7) 給出全部老師的信息。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select * from prof 8) 出全部老師的姓名及稅后工資額(稅額 5%)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname,sal*0.95 from prof 9) 找出全部選修課程的同學(xué)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select distinct sno from sc all在實(shí)際代碼中,不加,否則無(wú)效 10) 找出工資低于 1500 的職工的姓名、工資、系名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname,sal,dname f
44、rom prof,dept where sal1500 and prof.dno=dept.dno 11) 列出教授"數(shù)學(xué)'課程的老師的教工號(hào)及姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select prof.pno,pname from prof,pc,course where prof.pno=pc.pno and pc.cno=course.cno and course.cname="數(shù)學(xué)" 數(shù)學(xué),在查詢中應(yīng)當(dāng)為"哲學(xué)",在做只是鏈接時(shí),需要對(duì) pno 前加限制,否則會(huì)消失對(duì)象不明確 12) 列出工資在 500800 之
45、間的老師姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname from prof where sal between 500 and 800 13) 給出全部老師的姓名,所納稅額及稅后工資額(稅額 5%)。 該查詢的 select 語(yǔ)句: 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname,sal*0.05 as tax,sal*0.95 as income from prof %號(hào)不識(shí)別,應(yīng)當(dāng)寫成小數(shù)形式 14) 求每一課程的間接先行課(即先行課的先行課)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select c1.cno,c2.cno fro
46、m course as c1,course as c2 where c1.pcno=c2.cno 15) 找出工資比所在系主任工資高的老師姓名及工資。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select p1.pname,p1.sal from prof as p1,prof as p2,dept where p1.dno=dept.dno and dept.dean=p2.pno and p1.salp2.sal 16) 求選修了 c1 或 c2 課程的同學(xué)姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sname from s,sc where sc.sno=s.s
47、no and (sc.cno="c1" or sc.cno="c2") select sname from s,sc where s.sno=sc.sno and cno in ("c1","c2") 17) 列出姓名以"'打頭的老師的全部信息。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select * from prof where pname like "%" 18) 列出名稱中含有 4 個(gè)字符以上,且倒數(shù)第 3 個(gè)字符是"d',倒數(shù)第 2 個(gè)字符是&
48、quot;_'的老師的全部信息。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select * from prof where pname like "%d_"escape "" 19) 按系名升序列出老師姓名,所在系名,同一系中老師按姓名降序排列。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname,dean from prof,dept where prof.dno=dept.dno order by dean asc,pname desc 20) 求選修了 c1 或 c2 號(hào)而沒(méi)有選 c3 號(hào)課程的同學(xué)號(hào)。 該查詢的 sq
49、l 語(yǔ)句、消失的錯(cuò)誤及緣由: select distinct sno from sc where cno in ("c1","c2") and cno not in ("c3") 21) 列出各系的老師的最高、最低、平均工資。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select dno,max(sal),min(sal),avg(sal) from prof group by dno 22) 列出計(jì)算機(jī)系總分超過(guò) 300 分的同學(xué)的平均成果及學(xué)號(hào)。該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select avg(score),s
50、.sno from s,sc,dept where s.dno=dept.dno and dname="計(jì)算機(jī)" and s.sno=sc.sno group by s.sno having sum(score)=300 23) 列出選修了兩門課程以上的同學(xué)的平均成果及學(xué)號(hào)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select avg(score),sno from sc group by sno having count(*)=2 24) 求選修了課程的同學(xué)人數(shù)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select count(distinct sno) fr
51、om sc 25) 求各系 60 歲以上老師的平均工資。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select avg(sal) from prof where age60 group by dno 26) 找出年齡值為空的老師姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname from prof where age is null 27) 列出選修了 c1 號(hào)和 c2 號(hào)課程的同學(xué)的學(xué)號(hào)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sno from sc where cno="c1" and sno in (select sn
52、o from sc where cno="c2" ) 28) 找出平均成果最高的同學(xué)號(hào)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sno from sc group by sno having avg(score)=all (select avg(score) from sc group by sno) 子查詢返回的值多于一個(gè)。當(dāng)子查詢跟隨在 =、!=、=、= 之后,或子查詢用作表達(dá)式時(shí),這種狀況是不允許的。要加上 all 29) 求 s1 號(hào)同學(xué)所選課程的課程記錄。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select * from course w
53、here exists (select * from sc where sc.cno=course.cno and sc.sno="s1") 30) 列出選修了全部課程的同學(xué)名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sname from s where not exists (select * from course where not exists (select * from sc where sc.cno=course.cno and sc.sno=s.sno) ) 31) 列出至少選修了 s1 號(hào)同學(xué)選修的全部課程的同學(xué)名。 該查詢的 sql
54、語(yǔ)句、消失的錯(cuò)誤及緣由: select sname from s where not exists ( select * from sc sc1 where sc1.cno="s1" and not exists (select * from sc sc2 where sc2.cno=sc1.cno and sc2.sno=s.sno) ) 32) 找出全部只教授一門課程的老師姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select pname from prof where pno in (select pno from pc group by(pno) havi
55、ng count(pno)=1) unique 在查詢分析器中不識(shí)別,用 in 以及 group by 來(lái)實(shí)現(xiàn)相同功能 33) 找出至少選修了兩門課程的同學(xué)姓名。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sname from s where sno in (select sno from sc group by(sno) having count(sno)=2) 34) 找出平均成果及格的同學(xué)及其平均分?jǐn)?shù)。 該查詢的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: select sname,avg_score from s,(select sno,avg(score) from sc gr
56、oup by sno having avg(score)=60) as sc_avg(sno,avg_score) where s.sno=sc_avg.sno 利用派生關(guān)系解決屬性之間的問(wèn)題,重新生成一個(gè)臨時(shí)表并加以引用 5.4. insert 語(yǔ)句 35) 將平均成果大于 60 的同學(xué)加入到 excellent 中(先自行定義創(chuàng)建 excellent 表)。 該插入的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: create table excellent( sno varchar(10), score real) insert into excellent(sno,score) select sn
57、o,avg(score) from sc group by sno having avg(score)90 5.5. update 語(yǔ)句 36) 將老師工資上調(diào) 5%。 該更新的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: update prof set sal=sal*1.05 37) 將 d1 系系主任的工資改為該系的平均工資。 該更新的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: update prof set sal=(select avg(sal) from prof where dno="d1" ) where pno=(select dean from dept where dn
58、o="d1" ) 38) 工資超過(guò) 2021 的繳納 10%所得稅,其余的繳納 5%所得稅。求老師的稅后工資。 該更新的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: update prof set sal=sal*0.9 where sal2021 update prof set sal=sal*0.95 where sal=2021 39) 將計(jì)算機(jī)系同學(xué)的選課成果上調(diào) 20%。 該更新的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: update sc set score=score*1.2 where exists (select * from s,dept where s.dno=dep
59、t.dno and dept.dname="計(jì)算機(jī)" and s.sno=sc.sno) 5.6. delete 語(yǔ)句 40) 刪除張遼老師全部的任課記錄。 該刪除的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: delete from pc where pno in (select pno from prof where pname="張遼") delete 語(yǔ)句中不能使用連接,應(yīng)當(dāng)考慮使用子查詢 并且 from 后面的表明只能為一個(gè) 41) 清除 excellent 表中全部記錄。 該刪除的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: delete from excellent 42) 刪除低于平均工資的老師記錄。 該刪除的 sql 語(yǔ)句、消失的錯(cuò)誤及緣由: delete from prof where sal(sel
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年山東政法學(xué)院公開(kāi)招聘工作人員29人(長(zhǎng)期招聘崗位)考試備考題庫(kù)及答案解析
- 2026中國(guó)國(guó)際航空股份有限公司廣東分公司休息室就業(yè)見(jiàn)習(xí)崗招聘2人筆試備考試題及答案解析
- 2026能建綠氫(石家莊)新能源有限公司招聘6人筆試模擬試題及答案解析
- 2026山東能源集團(tuán)營(yíng)銷貿(mào)易有限公司所屬企業(yè)市場(chǎng)化招聘15人考試備考試題及答案解析
- 2026江蘇南京郵電大學(xué)招聘(人事代理)4人(第二批)考試備考試題及答案解析
- 2026年醫(yī)療護(hù)理職業(yè)防護(hù)培訓(xùn)
- 2026年紡織廠機(jī)械操作安全守則
- 2026浙江溫州市樂(lè)清市龍西鄉(xiāng)衛(wèi)生院招聘2人筆試備考試題及答案解析
- 2026上半年貴州事業(yè)單位聯(lián)考貴州中醫(yī)藥大學(xué)第一附屬醫(yī)院招聘48人筆試備考題庫(kù)及答案解析
- 2026年工程地質(zhì)勘察中實(shí)驗(yàn)室分析技術(shù)
- 經(jīng)典名著《紅樓夢(mèng)》閱讀任務(wù)單
- 古田會(huì)議學(xué)習(xí)課件
- 高寒地區(qū)建筑工程冬季施工技術(shù)規(guī)范研究
- 電流保護(hù)原理課件
- DBJT15-212-2021 智慧排水建設(shè)技術(shù)規(guī)范
- 民俗學(xué)課件萬(wàn)建中
- 能源與動(dòng)力工程專業(yè)培養(yǎng)目標(biāo)合理性評(píng)價(jià)分析報(bào)告
- 公司員工活動(dòng)室管理制度
- 2025年水晶手鏈?zhǔn)袌?chǎng)需求分析
- CJ/T 3066-1997內(nèi)磁水處理器
- 院內(nèi)急重癥快速反應(yīng)小組
評(píng)論
0/150
提交評(píng)論