版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
實訓(xùn)練習(xí)答案
實訓(xùn)1
4、
⑴INFo
因為存在部分函數(shù)依賴:員工號一姓名,性別部門號一部門名
即存在非主屬性對碼的部分函數(shù)依賴,因此不是2NF0
⑵
存在刪除異常。當(dāng)刪除E2員工信息時,同時也會刪除C1部門的信息。
(3)
員工(員工號,姓名,年玲,性別,所在部門號),主碼是員工號
部門(部門號,部門名),主碼是部門號
⑷
解決了數(shù)據(jù)冗余、插入異常和刪除異常的問題。
5、
(1)
倉庫(倉庫號,面積,電話號碼),主碼是倉庫號
零件(零件號,零件名稱,規(guī)格),主碼是零件號
零件存放(零件號,倉庫號,庫存數(shù)量),主碼是零件號+倉庫號
(2)
員工(員工編號,員工姓名,部門編號),土碼是員工號
部門(部門編號,部門名稱,部門所在城市),主碼是部門編號
項目(項目編號,項目名稱,預(yù)算),主碼是項目編號
員工參與項目(項目編號,員工編號,職務(wù),參加項目日期),主碼是項目編號+員工編號
實訓(xùn)2
E0
八//J
3、設(shè)如下關(guān)系,計算下列關(guān)系代數(shù):
R3
(1)YT
R31=TTYT(R)=
dc
fe
eD
⑵/?32=6p>5r)T=e(R)PQTY
9aef
7gef
⑶R3=Rx]V條件為[4]=[2]
pQR.TR.YW.TW.YB
2bcdcdm
2bcdcdn
9aefdfn
2befdfn
7gefdfn
7gcdcdm
7gcdcdn
4)R4=n12MlM6](q3H5](Rx0)
43]=[5](RxD)=
PQR.TR.YD.TD.Y
2bcdcd
9aefef
2befef
7gefef
7gcdcd
R4=口[2則,血(q3H5](RX°))=
QPD.Y
b2d
a9f
b2f
g7f
g7d
PQ
⑸R35=R+D=11
IJ
4、設(shè)有四個關(guān)系:
學(xué)生信息:S(S#,SNAME,AGE,SEX)
教師信息:T(T#,TNAME,AGE,SEX)
課程信息:C(C#,CNAME,T#)
選修:SC(S#,C#,GRADE)
請用關(guān)系代數(shù)表達(dá)式表示下列查詢語句:
(1)查詢年齡大于20歲的男生的學(xué)號與姓名。
"s#,SNAME("AGE>20andsex=0⑸)
(2)查詢劉明老師所謾課程的課程號、課程名。
"cC#CNAME("TJ#=C.T#andT.TNAME=,劉明,(TXC))
(3)查詢學(xué)號為S3的學(xué)生所學(xué)課程的課程名與任課教師名。
"cNAME,TNAME("sC.C#=C.C#andC.T#=T.T#andS#='S3'(SCxCxT))
5、設(shè)有以下關(guān)系:
學(xué)生(學(xué)號,姓名,性別,專業(yè),出生H期)
教師(教師編號,姓名,所在部門,職稱)
授課(教師編號,學(xué)號,課程編號,課程名稱,教材,學(xué)分,成績)
請用關(guān)系代數(shù)表達(dá)式表示下列查詢語句:
(1)查找教授“數(shù)據(jù)庫原理”課程的任課教師編號和姓名。
TT課程授課.教他編號=敦卿.敦他粕號and課程名稱='數(shù)據(jù)庫原理,(授課X教師))
教師。教如編號,姓名
(2)查找學(xué)習(xí)"英語〃課程的〃計算機(jī)應(yīng)用〃專業(yè)學(xué)生的學(xué)號、姓名和成績。
"學(xué)生.學(xué)號,姓名,成績(“授課?學(xué)號=學(xué)生?學(xué)號and課程名稱=,數(shù)據(jù)庫原理,and專業(yè)='計算機(jī)應(yīng)用'
(授課X學(xué)生))
實訓(xùn)3
1.
createtabledept3
(
dnointprimarykey,
dnamevarchar(20)notnull
createtablestudent3
(
snointprimarykey,
snamevarchar2(10)notnullunique,
sexchar(l),
dnoint,
foreignkey(dno)referencesdept3(dno)
);
createtableteacher3
(
tnointprimarykey,
tnamevarchar2(20)notnull
);
createtablecourse3
(
enoint,
cnamevarchar2(20)notnull,
tnoint,
creditint,
primarykey(eno),
foreignkey(tno)referencesteacher3(tno)
createtablesc3
snoint,
enoint,
gradeint,
primarykey(sno,eno),
foreignkey(sno)referencesstudent3(sno),
foreignkey(cno)referencescourse3(cno)
);
createviewcs_student3
asselect*fromstudents
wherednoin(selectdnofromdept3wheredname='信息技術(shù)’);
2.
altertablestudentsadd(sageint);
altertablestudentsmodify(sagesmallint);
3.
insertintodept3values(10,'信息技術(shù),);
insertintodept3values(20J軟件工程,);
insertintodept3values(30J網(wǎng)絡(luò)工程。;
insertintostudentsvalues(1001,,張?zhí)?,0,10,20);
insertintostudentsvalues(1002,'李蘭',1,10,21);
insertintostudentsvalues(1003,'文lj茜',1,20,21);
(馬朝陽)
insertintostudent3values1004,'',0z30,22;
insertintoteacher3values(101,'張星');
insertintoteacher3values(102,'李珊');
insertintoteacher3values(103,'趙天');
insertintocourse3values(l,'數(shù)據(jù)結(jié)構(gòu)101,4);
insertintocourse3values(2,'數(shù)據(jù)庫原理102,3);
insertintocourse3valuesa'離散數(shù)學(xué)103,4);
insertintocourse3values(4,'C語言程序設(shè)計,,101,2);
insertintosc3values(1001,1,80);
insertintosc3values(1001,2,85);
insertintosc3values(1002,1,78);
insertintosc3values(1002,2,82);
insertintosc3values(1002,3,86);
insertintosc3values(1003,1,92);
insertintosc3values(1003,3,90);
insertintosc3values(1004,4,90);
4.
select*fromstudent3;
selectsname,sagefromstident3
wheresex=l;
selectsno,grade
fromsc3
wherecno=landgradebetween80and89
orderbygradedesc;
selectdno,count(*)
fromstudents
groupbydno;
select*fromcs_student3;
5.
selectsname,sage
fromstudentss,dept3d
wheres.dno=d.dnoanddname='軟件工程,
andsage<=21andsex=l;
selectcourse.*,sc.sno,sc.g,ade
fromsc3,courses
whereo=oandcname=’數(shù)據(jù)結(jié)構(gòu)';
selects.sno,sname
fromsc3,course3c,student3s
whereo=oands.sno=sc.snoandcname=,數(shù)據(jù)結(jié)構(gòu),;
selectcount(sno)
fromstudentss,dept3d
wheres.dno=d.dnoanddname='軟件工程';
6.
updatestudent3setsage=sage+2wheresname='劉茜';
updatesc3setgrade=grade-10
whereeno=(selectenofromcourse3wherecname=,數(shù)據(jù)結(jié)構(gòu),)
andsno=(selectsnofromstudentswheresname='張?zhí)?);
7.
deletefromsc3wheresnoin(selectsnofromstudentswheresname='馬朝陽');
dropviewcs_student3;
實訓(xùn)5
2.
createuserulidentifiedbyul;
grantcreatesession,createtablespace,altertablespace,droptablespace,alterdatabasetoul;
3.
connectul/ul
createtablespacedatal
datafile'%oracle_base%\oradata\dbl\dsl.dbf'size50m
uniformsize128k;
4.
altertablespacedataladddatafile'%oracle_base%\oradata\dbl\ds2.dbf'size10m;
5.
alterdatabasedatafile'%oracle_base%\oradata\dbl\ds2.dbf'resize15m;
6.
createtemporarytablespacetempitempfile'%oracle_base%\oradata\dbl\templ.db「size10m;
7.
connsystem/systempwd
alteruseruldefaulttablespacedataltemporarytablespacetempi;
實訓(xùn)6
1.
connsystem/systempwd
createuseru2identifiedbyu2;
connu2/u2無法連接數(shù)據(jù)庫,因為缺少權(quán)限
connsystem/systempwd
grantcreatesessiontou2;
connu2/u2
connsystem/systempwd
alteruseru2identifiedbyu22;
connu2/u22
2.
connsystem/systempwd
createuseru3identifiedbyu3
defaulttablespaceusersquota2Monusers;
grantcreatesession,createtabletou3;
connu3/u3
createtabletl(emplDvarchar2(10),empNamevarchar2(10));
connsystem/systempwd
revokecreatetablefromu3;
connu3/u3
createtablet2(emplDvarchar2(10),empNamevarchar2(10));
3.
connsystem/systempwd
createrolemanagers;
grantcreatesession,createtable,createviewtomanagers;
select*fromrole_sys_priv$whererole='MANAGERS';
createuseru4identifiedbyu4
defaulttablespaceusersquota2Monusers;
grantmanagerstou4;
connu4/u4
createtablet2(idint);
4.
connsystem/systempwd
createuseru5identifiedbyu5;
createuseru6identifiedbyu6;
grantconnect,resourcetou5withadminoption;
connu5/u5
grantconnecttou6;
connsystem/systempwd
revokeconnect,resourcefromu5;
connu5/u5不能連接數(shù)據(jù)庫
connu6/u6可以連接數(shù)據(jù)庫
5.
connsystem/systempwd
createuseru7identifiedbyu7;
createuseru8identifiedbyu8;
grantconnect,resourcetou7,u8;
createtablet3(idint);
insertintot3values(l);
grantselectont3tou7withgrantoption;
connu7/u7
select*fromsystem.t3;
grantselectonsystem.t3tou8;
connu8/u8
select*fromsystem.t3;
connsystem/systempwd
revokeselectont3fromu7;
connu7/u7
select*fromsystem.t3;無法訪問
connu8/u8
select*fromsystem.t3;無法訪問
實訓(xùn)7
1.
createtabletl
(
enonumber(4)notnullprimarykey,
enamevarchar2(20)notnull,
sexchar(l)notnull,
birthdaydate,
salarynumber。,2)default(O)
);
2.
insertintotlvalues。,'丁一',0,null,null);
insertintotlvalues(2,'T—1,null,null);
3.
createtablet2
as
select*fromtlwheresex=0;
4.
createtablet3
as
select*fromtlwhere1=2;
5.
altertablet2addconstraintpklprimarykey(eno);
6.
createtableauthor
(
idnumber(3),
namevarchar2(20),
salnumber(6,2)
);
altertableauthoradd(addressvarchar2(100));
altertableauthorrenamecolumnsaltosalary;
altertableauthoraddconstraintpk_lprimarykey(id);
altertableauthoraddconstraintck_lcheckfsalarybetween0and10000);
altertableauthordropcolumnaddress;
droptableauthor;
7.
insertintostul
select*fromstu2;
8.
select*fromstul;
select*fromstu2;
updatestulsetname=(selectnamefromstu2wheresno=7i
wheresno=7;
實訓(xùn)8
1.
select*
fromemp8
wheredno=30;
2.
selectename,eno,dno
fromemp8
wherejob='CLERK,;
3.
selectinitcap(ename)
fromemp8;
4.
select*
fromemp8
wherelength(ename)=5;
5.
select*
fromemp8
whereenamelike'%R%';
6.
selectsubstr(ename,1,3)
fromemp8;
7.
select*
fromemp8
wheremonths_between(sysdate,hiredate)>=60;
8.
select*
fromemp8
orderbyename;
9.
selectename,hiredate
fromemp8
orderbyhiredate;
10.
selectenamejob,sal
fromemp8
orderbyjobdesc,sal;
11.
selectto_char(hiredate,'yyyy-mm-dd1)
fromemp8;
12.
selectconcat(concat(lower(ename),"'ssalaryis'),sal)
fromemp8;
或
selectlower(ename)||"'ssalaryis'||sal
fromemp8;
13.
select*
fromemp8
wherejobin('ANALYST;'SALESMAN');
或
select*
fromemp8
wherejob='ANALYST'orjob='SALESMAN';
14.
select*
fromemp8
wherednoin(selectdnofromdept8wheredname='research');
15.
select*
fromemp8
wheresal>(selectavg(sal)fromemp8);
16.
select*
from(selectdno,count(*),trunc(avg(sal))
fromemp8
groupbydno)
orderbydno;
17.
selectjob,min(sal),max(sal),avg(sal)
fromemp8
groupbyjob;
18.
select*
from(select*fromemp8orderbysaldesc)
whererownum<4;
19.
selectename,hiredate
fromemp8
wherehiredate=(selectmin(hiredate)fromemp8)
union
selectename,hiredate
fromemp8
wherehiredate=(selectmax(hiredate)fromemp8);
20.
selectename,
trunc(months_between(sysdate/hiredate))asaaa
fromemp8
orderbyaaadesc;
21.
selectsysdate
fromdual;
或
selectdistinctsysdate
fromemp8;
22.
selectto_char(sysdate,'mm-dd-yyyy')
fromdual;
23.
selectlast_day(sysdate)
fromdual;
實訓(xùn)9
1.
違反了主鍵的唯一性約束
createuniqueindexind_naneonemployee(name);
selectindex_name,table_name,status
fromuserjndexes
wheretable_name='EMPLOYEE';
違反了name字段建立的唯一性約束
2.
createviewv_stul
as
select*
fromstu
wheresex=O
orderbysnodesc;
select*fromv_stul;
selectcount(*)fromv_stul
wheresno>100;
dropviewv_stul;
3.
connsystem/systempwd
createsequencesno_seq
incrementby1
startwith100
maxvalue999
nocache
nocycle;
createtablestu(
snovarchar(12)primarykey,
namevarchar2(20),
ageint,
sexint);
insertintostuvalues('23A'||sno_seq.nextval,'aaa'z21,1);
insertintostuvalues('23A'||sno_seq.nextval,'bbb',20,0);
select*fromstu;
selectsno_seq.currvalfromdual;
selectsequence_namefromuser_sequences;
4.
connsystem/systempwd
createuseru9identifiedbyu9;
defaulttablespaceusers
quotaunlimitedonusers;
grantcreatesession,createtable,createpublicsynonymtou9;
connu9/u9
createtabletablel(idint);
insertintotablelvalues(l);
insertintotablelvalues(2);
createpublicsynonymtlfortablel;
select*fromtl;
connsystem/systempwd
select*fromdba_synonyms
wheretable_owner='U9';
實訓(xùn)10
1.
setserveroutputon
declare
inumber:=0;
v_sumnumber:=0;
begin
whilei<=100loop
v_sum:=v_sum+i;
i:=i+l;
endloop;
dbms_output.put_line(v_sum);
end;
2.
declare
v_enoemp8.eno%type;
v_enameemp8.ename%type;
begin
v_eno:=7369;
selectenameintov_ename
fromemp8
whereeno=v_eno;
dbms_output.put_line(v_ename);
end;
3.
declare
v_enoemp8.eno%type;
typerecord_emp8isrecord(
enamevarchar2(20),
salarynumber,
dnamevarchar2(40));
v_erecord_emp8;
begin
v_eno:=7900;
selectename,sal,dnameintov_e
fromemp8,dept8
whereemp8.dno=dept8.dnoandeno=v_eno;
dbms_output.put_line(v_e.ename);
dbms_output.put_line(v_e.salary);
dbms_output.put_line(v_e.dname);
end;
declare
v_dnoemp8.dno%type;
v_countint;
begin
v_dno:=10;
selectcount(*)intov_count
fromdept8wheredno=v_dno;
ifv_count=0then
dbms_output.put_line('該部門不存在');
else
casev_dno
when10then
updateemp8setsal=sal*l.lwheredno=v_dno;
when20then
updateemp8setsal=sal*0.95wheredno=v_dno;
else
updateemp8setsal=sal+300wheredno=v_dno;
endcase;
endif;
end;
實訓(xùn)11
1.
setserveroutputon
declare
cursoremp8_cursorisselect*fromemp8;
v_emp8emp8%rowtype;
begin
openemp8_cursor;
loop
fetchemp8_cursorintov_emp;
exitwhenemp8_curscr%notfound;
dbms_output.put_line(v_emp8.ename||v_emp8.sal);
endloop;
closeemp8_cursor;
end;
2.
altertabledept8add(totalpersonint);
declare
cursordept8_cursorisselectdnofromdept8forupdate;
v_dnodept8.dno%type;
v_countint:=0;
begin
opendept8_cursor;
loop
fetchdept8_cursorintov_dno;
exitwhendept8_cursor%notfound;
selectcount(*)intov_countfromemp8wheredno=v_dno;
updatedept8settotaberson=v_countwherecurrentofdept8_cursor;
endloop;
closedept8_cursor;
end;
/
selectdno,totalpersonfromdept8;
3.
insertintoemp8values(7749,'HANS','SALES',7782,,09-3月-15',2300,NULL,10);
declare
v_enoemp8.eno%type;
v_salemp8.sal%type;
exexception;
begin
v_eno:=7749;
selectsalintov_salfromemp8whereeno=v_eno;
ifv_sal<3000then
raiseex;
endif;
exception
whenno_data_foundthen
dbms_output.put_line('nodatafound');
whentoo_many_rowsthen
dbms_output.put_line('toomanyrows');
whenexthen
dbms_output.put_line(v_eno11'salaryistoolow');
end;
實訓(xùn)12
1.
setserveroutputon
createorreplaceprocedureselect_dname
(v_enoinempl2.eno%type,
v_dnameoutdeptl2.dname%type
)
is
begin
selectdnameintov_dname
fromempl2,deptl2
whereempl2.dno=deptl2.dnoandeno=v_eno;
exception
whenno_data_foundthen
dbms_output.put_line('nodatafound');
whenothersthen
dbms_output.put_line('unkownerror');
end;
/
調(diào)用該存儲過程:
varv_dnamevarchar2(20);
execselect_dname(7369,:v_dname);
printv_dname;
varv_dnamevarchar2(20);
execselect_dname(7777,:v_dname);
printv_dname;
2.
createorreplacefunctionvmax
(ainnumber,
binnumber,
cinnumber
)
returnnumber
is
v_resultnumber;
v_exexception;
begin
ifa<0orb<0orc<0then
raisev_ex;
endif;
ifa>bthen
ifa>cthen
v_result:=a;
else
v_result:=c;
endif;
else
v_result:=b;
ifc>bthen
v_result:=c;
endif;
endif;
returnv_result;
exception
whenv_exthen
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 護(hù)士培訓(xùn)考試題庫含答案
- 計劃調(diào)度員職位專業(yè)書籍及學(xué)習(xí)答案
- 會計面試題及財務(wù)實操能力考察
- 2025年便捷物流配送服務(wù)項目可行性研究報告
- 2025年現(xiàn)代化養(yǎng)殖技術(shù)研發(fā)項目可行性研究報告
- 2025年線上線下零售融合發(fā)展項目可行性研究報告
- 2025年車聯(lián)網(wǎng)及智能交通系統(tǒng)集成項目可行性研究報告
- 2026年閩西職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性考試題庫及參考答案詳解一套
- 2026年湖北省宜昌市單招職業(yè)適應(yīng)性測試題庫及答案詳解1套
- 2026年安徽醫(yī)學(xué)高等專科學(xué)校單招職業(yè)傾向性考試題庫及答案詳解1套
- 基建工程索賠管理人員索賠證據(jù)收集與審核指南
- AI智能生產(chǎn)平臺-AI+質(zhì)量管理
- 農(nóng)村山塘維修合同
- 量子點材料的發(fā)光性能研究與應(yīng)用
- 2025廣東廣州市衛(wèi)生健康委員會直屬事業(yè)單位廣州市紅十字會醫(yī)院招聘47人(第一次)筆試考試參考題庫及答案解析
- 中國外運招聘筆試題庫2025
- 建筑物拆除施工溝通協(xié)調(diào)方案
- 2025食品行業(yè)專利布局分析及技術(shù)壁壘構(gòu)建與創(chuàng)新保護(hù)策略報告
- 2025四川省教育考試院招聘編外聘用人員15人考試筆試模擬試題及答案解析
- 特許經(jīng)營教學(xué)設(shè)計教案
- 2025年智能消防安全系統(tǒng)開發(fā)可行性研究報告
評論
0/150
提交評論