SQL語句與關系代數(shù)習題--答案已做_第1頁
SQL語句與關系代數(shù)習題--答案已做_第2頁
SQL語句與關系代數(shù)習題--答案已做_第3頁
SQL語句與關系代數(shù)習題--答案已做_第4頁
全文預覽已結束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、 4一、選擇題1、SQL語言是( )語言。(SQL特點)(易)A)層次數(shù)據(jù)庫 B)網(wǎng)絡數(shù)據(jù)庫 C)關系數(shù)據(jù)庫 D)非數(shù)據(jù)庫答案:C2、SQL語言具有兩種使用方式,分別稱為交互式SQL和( )。(SQL語言使用方式)(易)A) 提示式SQL B)多用戶SQL C)嵌入式SQL D)解釋式SQL答案:C3、( )包括數(shù)據(jù)庫模式定義和數(shù)據(jù)庫存儲結構與存取方法定義。( )實現(xiàn)對DB的操作,包括查詢、插入、刪除、修改數(shù)據(jù)庫中的數(shù)據(jù)。( )用于數(shù)據(jù)保護,包括數(shù)據(jù)的安全性,完整性,并發(fā)控制和恢復等。(數(shù)據(jù)庫語言 DDL DML DCL)(中)A) 數(shù)據(jù)控制子語言 B)數(shù)據(jù)定義子語言 C)數(shù)據(jù)操縱子語言 D)

2、數(shù)據(jù)庫語言答案:B C A4、下列SQL語句中,實現(xiàn)數(shù)據(jù)檢索的語句是( ),修改表結構的是( ),修改屬性值的是( ),刪除表結構的是( ),刪除表記錄的是( )。(DROP TABLE, ALTER TABLE,UPDATE, DELETE,SELECT 語句)(難)A)SELECT B)DROP C)UPDATE D)ALTER E)DELETE答案:A D C B E二、用關系代數(shù)表達式及SQL語句描述關系查詢1、 設有如下關系表R、S和T: (易)R(BH, XM, XB, DWH)S(DWH, DWM)T(BH, XM, XB, DWH)寫出實現(xiàn)下列關系代數(shù)的SQL語句:1)2)3)

3、4)5)解:1) SELECT * FROM R WHERE DWH=100;2) SELECT XM,XB FROM R;3) SELECT XM,DWH FROM R WHERE XB=女;4) SELECT R.*,S.DWM FROM R, S WHERE R.DWH=S.DWH;5) SELECT XM,XB,DWH FROM R,S WHERE R.DWH=S.DWH AND XB=男;2、設有如下關系模式:student(NO, NAME , SEX ,BIRTHDAY, CLASS)teacher(NO,NAME,SEX,BIRTHDAY,PROF,DEPART) PROF為職

4、稱,DEPART為系別course(CNO, CNAME, TNO)score(NO, CNO, DEGREE) DEGREE 為成績寫出實現(xiàn)以下各題功能的SQL語句:(1) 查詢至少有2名男生的班號;(難)Select CLASS from student where SEX=男 Group by SEX Having Count(*)=2(2) 查詢不姓“王”的同學記錄;(易)Select * from student where NAME NOT Like 王%(3) 查詢每個學生的姓名和年齡;(難)Select NAME year(date()-year(BIRTHDAY) as ag

5、e From student (4) 查詢學生中最大和最小的birthday日期值;(中)Select max(BIRTHDAY), min(BIRTHDAY) From student(5) 查詢學生表的全部記錄并按班號和年齡從大到小的順序;(中)Select * from student order by CLASS DESC, BIRTHDAY DESC(6) 查詢男教師及其所上的課程;(中)Select NO,NAME, CNAME From teacher , course where teacher.NO= course.TNO and SEX=男(7) 查詢最高分同學的學號,課程

6、號和成績;(中)Select * from score where DEGREE= (select max(DEGREE) from score)(8) 查詢和“李軍”同性別并同班的所有同學的姓名;(中)Select NAME from student where SEX=(select SEX from student where NAME= 李軍 ) AND CLAEE= (select CLASS from student where NAME= 李軍 )(9) 查詢選修“數(shù)據(jù)庫系統(tǒng)概論”課程的男同學的成績表;(中)Select NO,NAME, CNO, CNAME DEGREE fr

7、om student, course, score Where student.NO= score.NO and course.CNO= score.CNO and CNAME= 數(shù)據(jù)庫系統(tǒng)概論 and SEX=男 Select * from score where NO in (select NO from student where Sex= 男) AND CNO= (select CNO from course where CNAME= 數(shù)據(jù)庫系統(tǒng)概論)(10) 查詢所有未講課的教師的姓名和所在系別;(難)Select NAME DEPART from teacher where NOT

8、 EXISTS (select * from score where teacher.NO=score.TNO)(11) 查詢“計算機系”教師所教課程的成績表;(難)Select * from score where CNO IN (select CNO from course where TNO in(select TNO from teacher where DEPART= 計算機系) Select Student.NO, Student.NAME, score.CNO, course.CNAME, Teacher.NO, Teacher.NAME, from student, teach

9、er,course,score where student.NO=score.NO and Course.CNO=score.CNO and Teacher.NO=Course.TNO and DEPART=計算機系(12) 查詢選修“3-105”課程的成績高于“109”號同學成績的所有同學的記錄;(難)Select student.NO, NAME, score.CNO,CNAME, DEGREE where score.CNO=3-105 and DEGREE (select DEGREE from score where NO=109 and CNO=3-105 ) and studen

10、t.NO=score.NO and score.CNO=course.CNO(13) 查詢最低分大于70,最高分小于90的學生的學號;(中)Select NO from score Group by NO having min(DEGREE)70 and max(DEGREE)90(14) 查詢成績在60到80之間的所有記錄;(中)Select * from score where DEGREE BETWEEN 60 AND 80(15) 查詢成績比該課程平均成績低的同學的成績表;(相關子查詢)(難)Select * from score x where DEGREE =2; (2)SELEC

11、T * FROM student WHERE NAME NOT LIKE 王*; (3)SELECT NAME,year(date()-year(birthday) as age FROM student; (4)SELECT MAX(BIRTHDAY), MIN(BIRTHDAY) FROM student ; (5)SELECT * FROM student ORDER BY CLASS,BIRTHDAY DESC; (6)SELECT , ame FROM teacher x, course y WHERE x.no=y.tno and x.sex=男; (7)SELECT

12、* FROM score WHERE degree=(SELECT max(degree) FROM score); (8)SELECT name FROM student WHERE sex=(SELECT sex FROM student WHERE name=李軍 ) and class=(SELECT class FROM student WHERE name=李軍); (9)SELECT * FROM score WHERE no IN(SELECT no FROM student WHERE sex=男) and cno=(SELECT cno FROM course WHERE

13、cname=數(shù)據(jù)庫系統(tǒng)概論); (10)SELECT name, depart FROM teacher t WHERE NOT EXIST (SELECT * FROM course c WHERE c.tno=t.no); (11)SELECT * FROM score s, teacher t, course c WHERE t.depart=計算機系 and t.no=c.tno and o=o; (12)SELECT * FROM student s, score sc WHERE s.no=sc.no and cno=3-105 and degree(SELECT degree FROM sc WHERE no=109 and cno=3-105); (13)SELECT no FROM score GROUP BY no HAVING min(degree)70 and max(degree)90; (14)SELECT * FROM score WHERE degree BETWEEN 60 AND 80; (15)SELECT * FROM score a WHERE degree (SELECT avg(degree) FROM score b WH

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論