




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上數(shù)據(jù)庫(kù) 上機(jī)實(shí)驗(yàn)報(bào)告1一、實(shí)驗(yàn)?zāi)康模豪斫釹QL Server數(shù)據(jù)庫(kù)的存儲(chǔ)結(jié)構(gòu),掌握SQL Server數(shù)據(jù)庫(kù)的建立方法和維護(hù)方法。二、實(shí)驗(yàn)內(nèi)容:在SQL Server環(huán)境下建立數(shù)據(jù)庫(kù)和維護(hù)數(shù)據(jù)庫(kù)。三、程序源代碼:-1CREATE DATABASE test1ON (NAME=test1_dat, FILENAME='f:DBdatatest1dat.mdf', SIZE= 10, MAXSIZE= 50, FILEGROWTH
2、= 5 )LOG ON(NAME=order_log, FILENAME='f:DBdatatest1log.ldf', SIZE= 5MB, MAXSIZE= 25MB, FILEGROWTH= 5MB) -2create database test2onprimary(name=test2_dat1,filename='f:DBdatatest2dat1.mdf'),(name=test2_dat2,filename='f:
3、DBdatatest2dat2.ndf'),(name=test2_dat3,filename='f:DBdatatest2dat3.ndf')log on(name=test2_log1,filename='f:DBdatatest2log1.ldf'),(name=test2_log2,filename='f:DBdatatest2log2.ldf')-3create database test3onprimary(name=test3_dat1,filename='f:DBdatatest3da
4、t1.mdf'),(name=test3_dat2,filename='f:DBdatatest3dat2.mdf'),filegroupg2(name=test3_dat3,filename='d:DBdatatest3dat3.ndf'),(name=test3_dat4,filename='d:DBdatatest3dat4.ndf'),filegroupg3(name=test3_dat5,filename='e:DBdatatest3dat5.ndf'),(name=test3_dat6,filename=
5、9;e:DBdatatest3dat6.ndf')log on(name=test3_log,filename='f:DBdatatest3log.ldf')-4alter database test1add file(name=test1new_dat,filename='f:DBdatatest1newdat.ndf',size=5MB)-5alter database test1modify file(name=test1_dat,size=15MB)-6dropdatabase
6、test3四、實(shí)驗(yàn)數(shù)據(jù)、結(jié)果分析:若沒(méi)有指定size,則默認(rèn)為1MB,沒(méi)有指定Maxsize,文件可以增長(zhǎng)到磁盤(pán)滿(mǎn)為止,沒(méi)有指定Filegrowth,則默認(rèn)為10%。五、總結(jié):CREATE DATABASE dataname 創(chuàng)建數(shù)據(jù)庫(kù)ALTER DATABASE database 修改數(shù)據(jù)庫(kù)DROP DATABASE dataname 刪除數(shù)據(jù)庫(kù)數(shù)據(jù)庫(kù)系統(tǒng)及應(yīng)用 上機(jī)實(shí)驗(yàn)報(bào)告2一、實(shí)驗(yàn)?zāi)康模赫莆毡砗退饕慕⒎椒氨斫Y(jié)構(gòu)的修改方法,并實(shí)踐DBMS提供的數(shù)據(jù)完整性功能,加深對(duì)數(shù)據(jù)完整性的理解。二、實(shí)驗(yàn)內(nèi)容:建立表,修改表結(jié)構(gòu),建立索引,數(shù)據(jù)完整性描述。三.、程序源
7、代碼: create database 訂單管理 create table 客戶(hù)(客戶(hù)號(hào) char(8) primary key check(客戶(hù)號(hào) like 'A-z%'),客戶(hù)名稱(chēng) varchar(40) not null,聯(lián)系人 char(8),地址 varchar(40),郵政編碼 char(6) check(郵政編碼 like &
8、#39;0-90-90-90-90-90-9'),電話 char(12) check(電話 like '10-90-90-90-90-90-90-90-90-90-90-9') create table 產(chǎn)品(產(chǎn)品號(hào) char(8) primary key check(產(chǎn)品號(hào) like 'A-ZA-Z%'),產(chǎn)品名稱(chēng) varchar(40),規(guī)格說(shuō)明 char(40)
9、 constraint uni unique,單價(jià) smallmoney constraint dj check(單價(jià)>0) create table 訂購(gòu)單(客戶(hù)號(hào) char(8) no tnull foreign key references 客戶(hù),訂單號(hào) char(8) primary key,訂購(gòu)日期 datetime def
10、ault getdate() create table 訂單名細(xì)(訂單號(hào) char(8) foreign key references 訂購(gòu)單,序號(hào) tinyint,產(chǎn)品號(hào) char(8) not null foreign key references 產(chǎn)品,數(shù)量 smallin tconstraint sl check(數(shù)量>0),primary
11、key(訂單號(hào),序號(hào)) -修改產(chǎn)品表-1alter table 產(chǎn)品drop constraint unialter table 產(chǎn)品alter column 規(guī)格說(shuō)明 varchar(40)alter table 產(chǎn)品add constraint uni unique (規(guī)格說(shuō)明)-2alter table 訂購(gòu)單 add 完成日期 datetime
12、 default null-3alter table 訂單名細(xì) drop constraint slalter table 訂單名細(xì) add constraint sl check(數(shù)量>0 and 數(shù)量<1000)-建立索引-1create index cus_idx on 客戶(hù)(客戶(hù)名稱(chēng))-2create unique index
13、0;gdn_nui on 產(chǎn)品(產(chǎn)品名稱(chēng))-3 創(chuàng)建表時(shí),primary key 隱式地創(chuàng)建了聚集索引,而一個(gè)表中只能有一個(gè)聚集索引。create clustered index oid_clus on 訂購(gòu)單(訂單號(hào)) -失敗-4create index item_idx on 訂單名細(xì)(訂單號(hào),序號(hào),數(shù)量 desc)數(shù)據(jù)庫(kù)系統(tǒng)及應(yīng)用 上機(jī)實(shí)驗(yàn)報(bào)告3一、實(shí)驗(yàn)?zāi)康模?/p>
14、為實(shí)驗(yàn)2建立的表設(shè)計(jì)一組數(shù)據(jù)進(jìn)行插入、刪除、修改等操作,并體會(huì)數(shù)據(jù)完整性約束的作用,加深對(duì)數(shù)據(jù)完整性及其約束的理解。二、實(shí)驗(yàn)內(nèi)容:數(shù)據(jù)的插入、更新和刪除。三.、程序源代碼: -1、部分記錄insert into 客戶(hù) values('C001','A公司','小明','北京','','7')insert into 客戶(hù) values('C002','B公司','小李','上海
15、','','4')insert into 客戶(hù)(客戶(hù)號(hào),客戶(hù)名稱(chēng)) values('C009','J商場(chǎng)') insert into 產(chǎn)品 values('GD001','iphone','4s','5000')insert into 產(chǎn)品 values('GD002','ipad','2g','5500&
16、#39;)insert into 產(chǎn)品(產(chǎn)品號(hào),產(chǎn)品名稱(chēng)) values('GD010','Mac Pro') insert into 訂購(gòu)單(客戶(hù)號(hào),訂單號(hào)) values('C001','or01')insert into 訂購(gòu)單(客戶(hù)號(hào),訂單號(hào)) values('C001','or02')insert into 訂購(gòu)單(訂單號(hào)) values('or19
17、39;) insert into 訂單名細(xì) values('or01','1','GD001','4')insert into 訂單名細(xì) values('or01','2','GD001','3')insert into 訂單名細(xì) values('or01','3','GD002','6')inser
18、t into 訂單名細(xì)(訂單號(hào),序號(hào),產(chǎn)品號(hào)) values('or14','28','GD006')-2delete from 客戶(hù) where 客戶(hù)號(hào)='C001' -受參照完整性約束delete from訂購(gòu)單 where 訂單號(hào)='or01' -受參照完整性約束-3update 訂購(gòu)單 set 訂單號(hào)=null where 客戶(hù)
19、號(hào)='C001' -受實(shí)體完整性約束update 訂購(gòu)單 set 客戶(hù)號(hào)='C011' where 訂單號(hào)='or04'-受參照完整性約束update 訂購(gòu)單 set 客戶(hù)號(hào)='C009' where 訂單號(hào)='or07' -更新成功update 訂單名細(xì) set 數(shù)量=0 where序號(hào)='9' -受用戶(hù)
20、定義完整性約束-4update 訂單名細(xì) set 數(shù)量=數(shù)量+10from 訂購(gòu)單where 訂購(gòu)單.訂單號(hào)=訂單名細(xì).訂單號(hào) and 客戶(hù)號(hào)='C002'-5delete from 訂單名細(xì)from 訂購(gòu)單where 訂購(gòu)單.訂單號(hào)=訂單名細(xì).訂單號(hào) and 客戶(hù)號(hào)='C002'四、實(shí)驗(yàn)數(shù)據(jù)、結(jié)果分析:-2在刪除客戶(hù)號(hào)為“C002”的記錄時(shí)無(wú)法刪除,因?yàn)榭蛻?hù)表被訂購(gòu)單表參照。刪除訂購(gòu)單號(hào)為“or01”的記錄時(shí)無(wú)法刪除,因?yàn)橛唵蚊?xì)表
21、參照訂購(gòu)單表。-3第一個(gè)更新根據(jù)實(shí)體完整性約束,訂單號(hào)是主關(guān)鍵字,不能為空值。第二個(gè)更新根據(jù)參照完整性約束,訂購(gòu)單表參照客戶(hù)表,而客戶(hù)表中沒(méi)有客戶(hù)號(hào)為“C011”的客戶(hù)。第四個(gè)更新根據(jù)用戶(hù)定義完整性約束,數(shù)量必須為正整數(shù)。-4使客戶(hù)號(hào)為C002的訂購(gòu)單的訂購(gòu)數(shù)量增加10.-5刪掉客戶(hù)號(hào)為C002的訂單名細(xì)記錄。五、總結(jié):插入:INSERT INTO <表名>(<列名>,<列名>)values(<表達(dá)式>,<表達(dá)式>) 更新:update <表名> set <列名>=<表達(dá)式>,
22、<列名>=<表達(dá)式>from<表名> where<邏輯表達(dá)式>刪除:DELETE FROM <表名>FROM <表名>WHERE <邏輯表達(dá)式>完整性約束影響插入、更新和刪除等操作數(shù)據(jù)庫(kù)系統(tǒng)及應(yīng)用 上機(jī)實(shí)驗(yàn)報(bào)告4一、實(shí)驗(yàn)?zāi)康模菏炀氄莆誗QL SELECT語(yǔ)句,能夠運(yùn)用該語(yǔ)句完成各種查詢(xún)。二、實(shí)驗(yàn)內(nèi)容:用SQL SELECT語(yǔ)句完成各種數(shù)據(jù)查詢(xún)。三.、程序源代碼:-1select * from 客戶(hù)-2select 客戶(hù)號(hào) from 訂購(gòu)單-3select * from 產(chǎn)品 where 單價(jià)>=5000-
23、4select * from 產(chǎn)品 where 單價(jià)>5000 and 產(chǎn)品名稱(chēng)='Macbook'-5select * from 產(chǎn)品 where 單價(jià)>6000 and 產(chǎn)品名稱(chēng) in('Macbook','ipad')-6select c.客戶(hù)名稱(chēng),c.聯(lián)系人,c.電話,o.訂單號(hào)from 客戶(hù) c,訂購(gòu)單 owhere o.訂購(gòu)日期 between '2011-10-30' and '2011-12-1'and c.客戶(hù)號(hào)=o.客戶(hù)號(hào) -7select distinct 客戶(hù)名稱(chēng),聯(lián)系
24、人,電話from 客戶(hù) c,產(chǎn)品 g,訂購(gòu)單 o,訂單名細(xì) dwhere 產(chǎn)品名稱(chēng)='iphone'and g.產(chǎn)品號(hào)=d.產(chǎn)品號(hào)and d.訂單號(hào)=o.訂單號(hào)and o.客戶(hù)號(hào)=c.客戶(hù)號(hào)-8select * from 訂單名細(xì)where 產(chǎn)品號(hào) in(select 產(chǎn)品號(hào)from 產(chǎn)品where 產(chǎn)品名稱(chēng)='Macbook')-9select * from 訂購(gòu)單where 訂單號(hào) in(select 訂單號(hào)from 訂單名細(xì)where 數(shù)量>10)-10select * from 產(chǎn)品 where 單價(jià) =(select 單價(jià) from 產(chǎn)品 whe
25、re 規(guī)格說(shuō)明='4s')-11select * from 產(chǎn)品 where 單價(jià) between 1000 and 5000-12select * from 客戶(hù) where 客戶(hù)名稱(chēng) like '%集團(tuán)'-13select * from 客戶(hù) where 客戶(hù)名稱(chēng) not like '%商場(chǎng)'-14select * from 產(chǎn)品 order by 單價(jià)-15select *from 產(chǎn)品order by 產(chǎn)品名稱(chēng),單價(jià)-16select COUNT(產(chǎn)品號(hào))from 產(chǎn)品-17select SUM(數(shù)量)from 訂單名細(xì)where 產(chǎn)品號(hào)
26、=(select 產(chǎn)品號(hào)from 產(chǎn)品where 產(chǎn)品名稱(chēng)='ipad')-18select SUM(數(shù)量*單價(jià)) 總金額from 產(chǎn)品,訂單名細(xì)where 產(chǎn)品.產(chǎn)品號(hào)=訂單名細(xì).產(chǎn)品號(hào)and 產(chǎn)品名稱(chēng)='ipod nano'-19select COUNT(distinct 訂單號(hào))as 訂購(gòu)單個(gè)數(shù),AVG(數(shù)量*單價(jià))as 平均金額from 產(chǎn)品,訂單名細(xì)where 產(chǎn)品.產(chǎn)品號(hào)=訂單名細(xì).產(chǎn)品號(hào)-20select 訂單號(hào),COUNT(訂單號(hào)) 項(xiàng)目數(shù),SUM(g.單價(jià)*o.數(shù)量) 總金額from 產(chǎn)品 g,訂單名細(xì) owhere g.產(chǎn)品號(hào)=o.產(chǎn)品號(hào)gr
27、oup by 訂單號(hào)-21select i.訂單號(hào),MAX(數(shù)量*單價(jià)) 最高金額,MIN(數(shù)量*單價(jià)) 最低金額from 訂購(gòu)單 o,產(chǎn)品 g,訂單名細(xì) iwhere o.訂單號(hào)=i.訂單號(hào)and g.產(chǎn)品號(hào)=i.產(chǎn)品號(hào)and 產(chǎn)品名稱(chēng)='iphone'group by i.訂單號(hào)-22select 訂單號(hào),COUNT(*) 項(xiàng)目數(shù),AVG(數(shù)量*單價(jià)) 平均金額from 產(chǎn)品 g,訂單名細(xì) iwhere g.產(chǎn)品號(hào)=i.產(chǎn)品號(hào)group by 訂單號(hào)having COUNT(*)>=2-23select 客戶(hù)名稱(chēng),聯(lián)系人,電話,訂單號(hào)from 客戶(hù) c,訂購(gòu)單 owh
28、ere c.客戶(hù)號(hào)=o.客戶(hù)號(hào)and 訂購(gòu)日期 is null-24select 客戶(hù)名稱(chēng),聯(lián)系人,電話,訂單號(hào),訂購(gòu)日期from 客戶(hù),訂購(gòu)單where 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)and 訂購(gòu)日期>'2011-10-10'-25select *from 產(chǎn)品 outawhere 單價(jià)=(select MAX(單價(jià))from 產(chǎn)品 innerawhere outa.產(chǎn)品名稱(chēng)=innera.產(chǎn)品名稱(chēng))-26select 客戶(hù)號(hào)from 客戶(hù)where not exists(select *from 訂購(gòu)單where 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào))-27select *fr
29、om 客戶(hù)where exists(select *from 訂購(gòu)單where 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào))-28select 產(chǎn)品名稱(chēng)from 產(chǎn)品where 單價(jià)= any(select 單價(jià)/2 from 產(chǎn)品)-29select 產(chǎn)品名稱(chēng)from 產(chǎn)品where 單價(jià) >all(select max(單價(jià)) from 產(chǎn)品)-30-crossselect * from 客戶(hù) cross join 訂購(gòu)單where 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)-innerselect * from 客戶(hù) inner join 訂購(gòu)單on 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)-leftselec
30、t 客戶(hù).*,訂單號(hào),訂購(gòu)日期from 客戶(hù) left join 訂購(gòu)單on 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)-rightselect 客戶(hù).*,訂單號(hào),訂購(gòu)日期from 客戶(hù) right join 訂購(gòu)單on 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)-fullselect 客戶(hù).*,訂單號(hào),訂購(gòu)日期from 客戶(hù) full join 訂購(gòu)單on 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)數(shù)據(jù)庫(kù)系統(tǒng)及應(yīng)用 上機(jī)實(shí)驗(yàn)報(bào)告5一、實(shí)驗(yàn)?zāi)康模豪斫庖晥D的概念,掌握視圖的使用方法。二、實(shí)驗(yàn)內(nèi)容:定義視圖,并在視圖上完成查詢(xún)、插入、更新和刪除操作。三.、程序源代碼: -1-1)、基于單個(gè)表按投影操作定義視圖create vi
31、ew v_cus asselect 客戶(hù)號(hào),客戶(hù)名稱(chēng)from 客戶(hù)-使用select * from v_cus-2)、基于單個(gè)表按選擇操作定義視圖create view v_order asselect *from 訂購(gòu)單where 客戶(hù)號(hào)='C001'-使用select * from v_order-3)、基于單個(gè)表按選擇和投影操作定義視圖create view v_cuss asselect 客戶(hù)名稱(chēng),聯(lián)系人,電話from 客戶(hù)where 客戶(hù)號(hào)='C003'-使用select * from v_cuss-4)、基于多個(gè)表根據(jù)連接操作定義視圖create v
32、iew v_join asselect 客戶(hù).*,訂單號(hào),訂購(gòu)日期from 客戶(hù) join 訂購(gòu)單on 客戶(hù).客戶(hù)號(hào)=訂購(gòu)單.客戶(hù)號(hào)-使用select * from v_join-5)、基于多個(gè)表根據(jù)嵌套查詢(xún)定義視圖create view v_item asselect * from 訂單名細(xì)where 產(chǎn)品號(hào) in(select 產(chǎn)品號(hào)from 產(chǎn)品where 產(chǎn)品名稱(chēng)='Macbook')-使用select * from v_item-6)、查定義含有虛字段的視圖create view v_items(訂單號(hào),序號(hào),產(chǎn)品號(hào),數(shù)量,總金額) asselect i.*,i.數(shù)量*g.單價(jià)from 訂單名細(xì) i,產(chǎn)品 gwhere i.產(chǎn)品號(hào)=g.產(chǎn)品號(hào)-使用select * from v_items-2-在視圖上查詢(xún)select * from v_
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 寵物救生與急救操作考核試卷
- 模具超聲波無(wú)損檢測(cè)技術(shù)考核試卷
- 核電站設(shè)計(jì)與建設(shè)中的質(zhì)量監(jiān)督與驗(yàn)收標(biāo)準(zhǔn)考核試卷
- 漆器工藝品目標(biāo)消費(fèi)群體研究考核試卷
- 竹材采運(yùn)信息化與大數(shù)據(jù)分析考核試卷
- 電磁場(chǎng)掃描與探測(cè)教具考核試卷
- 租賃店鋪的社區(qū)關(guān)系維護(hù)考核試卷
- 煤炭行業(yè)人才培養(yǎng)與引進(jìn)考核試卷
- 科爾沁藝術(shù)職業(yè)學(xué)院《文化產(chǎn)業(yè)管理概論》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧財(cái)貿(mào)學(xué)院《藝術(shù)市場(chǎng)營(yíng)銷(xiāo)與實(shí)踐》2023-2024學(xué)年第一學(xué)期期末試卷
- 大米生產(chǎn)與食品安全
- NES-3000 ECDIS電子海圖顯示與信息系統(tǒng)操作手冊(cè)
- DB11-T 311.1-2019 城市軌道交通工程質(zhì)量驗(yàn)收標(biāo)準(zhǔn) 第1部分:土建工程
- 八年級(jí)下冊(cè)歷史:?jiǎn)柎鹗綇?fù)習(xí)提綱
- 2025年中國(guó)氫氣傳感器行業(yè)市場(chǎng)深度分析及投資策略研究報(bào)告
- 幼兒園親子采摘活動(dòng)策劃方案四篇
- 人教版(2024)八年級(jí)下冊(cè)物理第十章《浮力》第4節(jié) 跨學(xué)科實(shí)踐制作微型密度計(jì) 教案
- 2025方大特鋼科技股份限公司招聘59人高頻重點(diǎn)提升(共500題)附帶答案詳解
- 全國(guó)清華版信息技術(shù)小學(xué)一年級(jí)下冊(cè)新授課 第12課 在網(wǎng)上交流信息 說(shuō)課稿
- 綜合管理部門(mén)車(chē)輛安全生產(chǎn)職責(zé)模版(2篇)
- 辦公樓拆除施工方案
評(píng)論
0/150
提交評(píng)論