【正文】
9。C0739。C0539。各屬性名為Sno學(xué)號(hào),Cno課程號(hào)和Grade考試成績,要求Sno和Cno不能為空,且取值唯一,Sno+ Cno為鍵碼。,39。S0139。insert into Reports(Sno,Cno,Grade)values(39。,90)。C0239。,39。S0339。insert into Reports(Sno,Cno,Grade)values(39。,90)。C0339。 create unique index Couo on Courses(Cno)。2.掌握基本表的插入、刪除與修改。五、實(shí)驗(yàn)學(xué)時(shí):2學(xué)時(shí)六、實(shí)驗(yàn)重點(diǎn)及難點(diǎn)1.TSQL語句對(duì)基本表的定義進(jìn)行刪除與修改,并插入基本表數(shù)據(jù)。 在Students 表中增加屬性列Sentrancedate②將Sage(年齡)的數(shù)據(jù)類型改為SMALLINT型。 SQL語句:alter table Students drop constraint UQ__Students__52723D276262D465。 因?yàn)镾tudents表中有Reports表的外碼,故只有刪除Repors表后才能刪除Students表。 向表中添加元組①將一個(gè)學(xué)生元組(S01,王建平,男,21,計(jì)算機(jī))添加到基本表Students中。王建平39。自動(dòng)化39。S0239。女39。insert into Students (Sno,Sname,Ssex,Sage,Sdept)values (39。,39。)。李偉39。數(shù)學(xué)39。,39。,18,39。S0639。男39。執(zhí)行結(jié)果:③向Courses表插入元組(‘C01’,’英語’,’’,4)。英語39。運(yùn)行結(jié)果:④請(qǐng)同學(xué)們用這個(gè)命令,將其余6門課程的信息插入Courses表中。數(shù)據(jù)結(jié)構(gòu)39。Insert into Courses (Cno,Cname,Pre_Cno,Credits )values (39。,39。C0439。C0339。,39。,3)。網(wǎng)絡(luò)原理39。insertinto Courses (Cno,Cname,Pre_Cno,Credits )values (39。,39。 SQL語句: insert into Reports(Sno,Cno,Geade)values(39。,92)。運(yùn)行結(jié)果為: (Sname)、學(xué)號(hào)(Sno)、所在系(Sdept)。運(yùn)行結(jié)果為: (Sno)和姓名 (Sname)。其命令為:select Sname,Sage from Students where Sage between 18 and 22。其命令為:select Sno,Sname,Sage from Students where Sdept in(39。,39。其命令為: select Sname,Sno,Ssex from Students where Sname like 39。DB_設(shè)計(jì)39。 escape 39。其命令為:select *from Reportswhere Grade is null。其命令為:select count(*) 39。其命令為:select count(distinct Sno) 39。其命令為:select avg(Grade) 39。 運(yùn)行結(jié)果為: 查詢選修C01號(hào)課程的學(xué)生最高分?jǐn)?shù)。C0139。2016Sage39。 39。 , LOWER (Sdept ) 39。 運(yùn)行結(jié)果為: 案例7:查詢計(jì)算機(jī)系全體學(xué)生的名單 命令為:select Sname from Student where Sdept =39。 運(yùn)行結(jié)果為: 案例10:查詢年齡在20~23歲(包含20歲和23歲)之間的學(xué)生的姓名、系別和年齡 命令為:select Sname,Sdept ,Sage from Student where Sage between 20 and 23。,39。)。MA39。 運(yùn)行結(jié)果為: 案例14:查詢學(xué)號(hào)為201212121的學(xué)生的詳細(xì)情況 命令為:select * from Student where Sno=39。 運(yùn)行結(jié)果為: 案例16:查詢姓“歐陽”且全名為三個(gè)漢字的學(xué)生的姓名 命令為:select Sname from Student where Sname like 39。 運(yùn)行結(jié)果為: 案例18:查詢所有不姓劉的學(xué)生的姓名、學(xué)號(hào)和性別 命令為:select Sname ,Sno ,Ssex from Student where Sname not like 39。 escape 39。 escape 39。其命令為: 命令為:select Sno ,Cno from SC where Grade is null。and Sage 20。學(xué)生總?cè)藬?shù) 39。 from Student 。2.掌握連接、嵌套和集合查詢的各種使用方法。四、注意事項(xiàng)1.注意TSQL各種運(yùn)算符、控制語句的功能及使用方法。3.多重嵌套的使用。 命令為:select , from Courses first,Courses second where first .Pre_Cno =second .Cno 。)。 ) ) 運(yùn)行結(jié)果為:5.查詢與“S04”號(hào)學(xué)生在同一個(gè)系學(xué)習(xí)的學(xué)生學(xué)號(hào)(Sno)、姓名(Sname)和系名(Sdept)。運(yùn)行結(jié)果為:6.查詢非自動(dòng)化系的不超過自動(dòng)化系所有學(xué)生的年齡的學(xué)生姓名(Sname)和年齡(Sage)。自動(dòng)化39。)。運(yùn)行結(jié)果為:8.查詢選修了所有課程的學(xué)生姓名(Sname)和所在系。計(jì)算機(jī)39。 命令為:select Student.* ,SC .* from Student ,SC where =SC .Sno 。 運(yùn)行結(jié)果為: 例3查詢每一門課的間接先修課(即先修課的先修課)。 命令為:select Sno,Sname,Sdept from Student where Sdept in ( select Sdept from Student where Sname =39。 命令為:select Student .Sno ,Sname from Student ,SC,Course where = and = and =39。CS39。CS39。 命令為: select Sname ,Sdept from Student where Sno in (select Sno from SC where Cno =39。139。139。)。20151512239。 union select * from Student where Sage =39。) union select * from Student where Sno in (select Sno from SC where Cno =39。CS39。139。 運(yùn)行結(jié)果為: 例18 查詢計(jì)算機(jī)系的學(xué)生與年齡不大于19歲的學(xué)生的差集 命令為:select * from Student where Sdept =39。CS39。二、實(shí)驗(yàn)任務(wù)設(shè)計(jì)一個(gè)簡單的設(shè)備管理數(shù)據(jù)庫系統(tǒng)(不限),參考課本218頁。 對(duì)數(shù)據(jù)進(jìn)行插入、修改、刪除、查詢。3. 靈活運(yùn)用索引、視圖、存儲(chǔ)過程、觸發(fā)器等。 邏輯模型: 物理模型:5. 建立好完整的物理模型后,可以用工具(數(shù)據(jù)庫)生成SQL代碼: 物資管理數(shù)據(jù)庫的SQL代碼如下:/*==============================================================*//* DBMS name: Microsoft SQL Server 2008 *//* Created on: 2016/11/5 14:19:34 *//*==============================================================*/if exists (select 1 from sysobjects where id = object_id(39。) drop table 倉庫goif exists (select 1 from sysobjects where id = object_id(39。) drop table 供應(yīng)goif exists (select 1 from sysobjects where id = object_id(39。) drop table 供應(yīng)商goif exists (select 1 from sysobjects where id = object_id(39。) drop table 庫存goif exists (select 1 from sysobjects where id = object_id(39。) drop table 職工goif exists (select 1 from sysobjects where id = object_id(39。) drop table 零件goif exists (select 1 from sysobjects where id = object_id(39。) drop table 項(xiàng)目goif exists (select 1 from sysobjects where id = object_id(39。) drop table 領(lǐng)導(dǎo)go/*==============================================================*//* Table: 倉庫 *//*==============================================================*/create table 倉庫 ( 倉庫號(hào) char(10) not null, 職工號(hào) char(10) not nu