【正文】
是狼就要練好牙,是羊就要練好腿。項目39。職工39。供應(yīng)商39。倉庫39。 四、注意事項特別注意創(chuàng)建數(shù)據(jù)庫中數(shù)據(jù)的完整性約束。and Sage 19。 and Sno in (select Sno from SC where Cno=39。239。 and not exists (select * from SC SCZ where = and = ))。)。139。) and Sdept 39。劉晨39。 運行結(jié)果為:例2 查詢選修2號課程且成績在90分以上的所有學生學號和姓名 命令為:select ,Sname from Student ,SC where Student .Sno = and =39。 命令為:select Sname ,Sdept from Students where not exists (select * from Courses where not exists (select * from Reports where Sno = and Cno= ))。 運行結(jié)果為:7.查詢所有選修了編號為“C01”課程的學生姓名(Sname)和所在系(Sdept)。 命令為:select Sno ,Sname ,Sdept from Students where Sdept in (select Sdept from Students where Sno=39。 運行結(jié)果為:3.查詢與“李偉”在同一個系學習的學生學號(Sno)、姓名(Sname)和系名(Sdept)。2.注意各種系統(tǒng)函數(shù)的調(diào)用方法。 運行結(jié)果為:. . . .實驗四 連接、嵌套和集合查詢一、實驗?zāi)康募耙螅?1.熟練掌握連接、嵌套和集合查詢的使用。 運行結(jié)果為:案例24:查詢?nèi)w學生情況,查詢結(jié)果按所在系的系名(Sdpet)升序排列,同一系中的學生按年齡(Sage)降序排列。\39。劉%39。20121512139。 運行結(jié)果為: 案例13:查詢不是計算機系、數(shù)學系和信息系的學生的姓名和性別 命令為:select Sname ,Ssex from Student where Sdept not in(39。 運行結(jié)果為: 案例11:查詢年齡不在20~23歲之間的學生的姓名、系別和年齡 命令為:select Sname,Sdept ,Sage from Student where Sage not between 20 and 23。LOWER (Sdept)39。 from Student 。其命令為:select max(Grade) 39。選修課總?cè)藬?shù)39。 運行結(jié)果為: 查詢?nèi)w學生情況,查詢結(jié)果按所在系的系名(Sdpet)升序排列,同一系中的學生按年齡(Sage)降序排列。運行結(jié)果為: 查詢以DB_開頭,且倒數(shù)第2個漢字字符為“設(shè)”的課程的詳細情況。計算機39。運行結(jié)果為: 查詢年齡不在1822歲之間的學生姓名(Sname)及年齡(Sage)。這是一個無條件的投影查詢,其命令為: select Sname,Sno,Sdept from Students 。S0139。C0739。insertinto Courses (Cno,Cname,Pre_Cno,Credits )values (39。,3)。C0239。,39。,39。,20,39。數(shù)學39。)。insert into Students (Sno,Sname,Ssex,Sage,Sdept)values (39。S0339。,39。,39。SQL語句: drop table Reports。 SQL語句:alter table Students alter column Sage smallint。三、操作要點:、刪除與修改分別是INSERT、DROP和UPDATE 四、注意事項:,命令執(zhí)行完后要查看表的變動刷新表。,75)。S0339。C0339。insert into Reports(Sno,Cno,Grade)values(39。,39。 使用SQL語句創(chuàng)建表Reports:create table Reports( Sno char(9) not null, Cno char (9) not null, Grade smallint, primary key (Sno,Cno), foreign key (Sno)references Students(Sno), foreign key (Cno)references Courses(Cno))。,39。C0639。insertinto Courses (Cno,Cname,Pre_Cno,Credits )values (39。,2)。C0539。,39。再次使用查詢語句select * from Students。S0639。,39。李偉39。,39。女39。,21,39。用select * from Students語句。 :create database Company;執(zhí)行完成創(chuàng)建數(shù)據(jù)庫Company。. . . .課程編號: D04400050學 號: 201540410126 據(jù)庫系統(tǒng)(雙語)實驗報告教 學 院計算機學院課程名稱數(shù)據(jù)庫系統(tǒng)(雙語)專業(yè) 班級計算機科學與技術(shù)2015(1)班姓 名甘全中指導教師衛(wèi)鋒2016年12月15日學習參考實驗一 創(chuàng)建數(shù)據(jù)庫和表一、實驗?zāi)康募耙螅?.了解SQL SERVER數(shù)據(jù)庫的邏輯結(jié)構(gòu)和物理結(jié)構(gòu)2.了解表的結(jié)構(gòu)特點3.了解SQL SERVER的基本數(shù)據(jù)結(jié)構(gòu)二、實驗任務(wù):1.學會在企業(yè)管理器中創(chuàng)建數(shù)據(jù)庫和表2.學會在TSQL語句創(chuàng)建數(shù)據(jù)庫和表三、操作要點:1.啟動企業(yè)管理器,并創(chuàng)建數(shù)據(jù)庫和表2.啟動SQL查詢分析器3.掌握創(chuàng)建數(shù)據(jù)庫和表分別是CREATE DATABASE和CREATE TABLE四、注意事項:1.在Microsoft SQL Server 2000的查詢分析器(Query Analyzer)中使用單條SQL語句,其末尾不需要分號“;”作為命令結(jié)尾標記。 即完成創(chuàng)建數(shù)據(jù)庫Company。查詢已建表:2. 。自動化39。,19,39。女39。,39。黃河39。,39。運行結(jié)果: ,各屬性為Cno課程號, Cname課程名, Pre_Cno先修課程號, Credits學分,要求Cno和Cname不能為空值,Cno取值唯一,且為鍵碼。null39。,2)。insertinto Courses (Cno,Cname,Pre_Cno,Credits )values (39。C0539。,39。操作系統(tǒng)39。使用SQL語句插入數(shù)據(jù):insert into Reports(Sno,Cno,Grade)values(39。C0339。S0239。,82)。,39。查詢結(jié)果: 6. 在相關(guān)表上建立索引。、刪除與修改等更新操作時,要保證數(shù)據(jù)的完整性。 將STudents表中的Sage的數(shù)據(jù)類型改為smallint。drop table Students 。男39。劉華39。,39。S0439。insert into Students (Sno,Sname,Ssex,Sage,Sdept)values (39。)。數(shù)學39。 39。C0539。,2)。insertinto Courses (Cno,Cname,Pre_Cno,Credits )values (39。C0639。,39。,39。運行結(jié)果為: 查詢選修了課程的學生學號。其命令為: select Sname,Sage from Students where Sage not between 18 and 22。)。其命令為:select *from Courses where Cname like 39。其命令為: select * from Students order by Sdept ,Sage desc。from Reports。C01號課程最高分39。 運行結(jié)果為: 案例5:查詢?nèi)w學生的姓名、出生年份和所在院系,要求用小寫字母表示系名 命令為:select Sname ,39。 from Student 。 運行結(jié)果為: 案例12:查詢計算機系、數(shù)學系和信息系的學生的姓名和性別 命令為:select Sname ,Ssex from Student where Sdept in(39。CS39。 運行結(jié)果為: 案例15:查詢所有姓劉的學生的姓名、學號和性別 命令為:select Sname ,Sno,Ssex from Student where Sname like 39。 運行結(jié)果為: 案例19:查詢DB_設(shè)計課程的課程號和學分 命令為:select Cno ,Ccredit from Course where Cname like 39。 運行結(jié)果為:案例21:某些學生選修課程后沒有參加考試,所以有選課記錄,但沒有考試成績。其命令為: 命令為:select * from Student order by Sdept ,Sage desc。2.學習各種連接、嵌套和集合查詢方法。五、實驗學時:4學時六、實驗重點及難點1.明白兩個表之間的聯(lián)系是通過公共屬性實現(xiàn)的。 命令為:select Sno ,Sname,Sdept from Students where Sdept in (select Sdept from Students where Sname =39。S0439。 命令為:select Sname ,Sdept from Students where Sno in(select Sno from Reports where Cno=39。 運行結(jié)果為:9.查詢計算機科學系的學生或年齡不大于20歲的學生信息。239。)。CS39。)。 或:select Sname ,Sdept from Student where not exists (select * from SC where Sno = and C