资源描述:
《第一次上机练习_习题_结果文库》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、习题1请根据给出的数据库表结构來回答相应问题:DEPT(DEPTNOINT,DNAMEVARCIIAR(M),LOGVARCHAR(13));EMP(EMPNQINT,ENAMEVARCHAR(10),JOBVARCHAR(9),MGRINT,HIREDATEDATE,SALFLOAT,COMMFLOAT,DEPTNOINT);BONUS(ENAMEVARCHAR(10),JOBVARCHAR(9),SALINT,COMM1NT);SALGRADE(GRADEINT,LOSALINT,HISALINT);其中表中包含如下数据:DEPT表:DEPTNO
2、DNAME
3、
4、LOC」10ACCOUNTINGNEWYORK20RESEARCHDALLAS30SALESCHICAGO40OPERATIONSBOSTONEMP表:EMPNOIENAMEJOBMGRJHIREDATESALICOMMDEPTNO^J_I7369ISMITHCLERK75661980-12-1700:00:00.000800NULL202_7499ALLENSALESMAN76981981-02-2000:00:00.00016003003037521WARDSALESMAN76981981-02-2200:00:00.00012505003047566JONE
5、SMANAGER78391981-04-0200:00:00.0002975NULL2057654MARTINSALESMAN76981981-09-2800:00:00.000125014003067698BLAKEMANAGER78391981-05-0100:00:00.0002850NULL301__7782CLARKMANAGER78391981-06-0900:00:00.0002450NULL10_8_7788SCOTTANALYST75661987-06-1300:00:00.0003000NULL2097839KINGPRESIDENTNULL1
6、981-11-1700:00:00.0005000NULL10107844TURN...SALESMAN76981981-09-0800:00:00.0001500030117876ADAMSCLERK77881987-06-1300:00:00.0001100NULL20127900JAMESCLERK76981981-12-0300:00:00.000950NULL30137934MILLERCLERK77821982-01-2300:00:00.0001300NULL10SALGRADE表:GRADELOSALHISAL1700120021201140031
7、4012000420013000530019999BONUS表:无数据根据上面描述完成下面问题:(注着:注意保存脚木,尤其是DDL和DML,以便进行数据还原)DDL1.写出上述表的建表语句。此外,在DEPT上创建名为”PK_DEPT”的主键约束,在EMP表上创建名为”PK_EMP”的主键约束以应指向表DEPT的外键约束”FK_DEPTNO”o命令:createtableDEPT(DEPTNOint,DNAMEnvarchar,LOCnvarchar,primarykey(pkdept));CreatetableEMP(EMPNOint,ENAMEnvarchar,
8、JOBnvarchar,MGRint,HIREDATEdatetime,SALint,COMMfloat,DEPTNOint,primarykey(pk_emp),foreginkey(fk_dept.no)referencesdept);DML2.给岀相应的INSERT语句来完成题中给出数据的插入。命令:insert(“1”,”accounting,”null”)3.将所有员工的工资上浮10%.然后查询员工姓名、薪水、补助。(emp.sal为工资,omp.comm为补助)命令:selectename,sal*1.1,commFromemp结果:enamesalc
9、omm1SMITH880NULL2ALLEN17603003WARD13755004JONES3272.5NULL5MARTIN137514006BLAKE3135NULL7CLARK2695NULL8SCOTT3300NULL9KING5500NULL10TURNER1650011ADAMS1210NULL12JAMES1045NULL13MILLER1430NULL单表查询1.查看EMP表中部门号为10的员工的姓名,职位,参加工作时间,工资。命令:selectenamejob,hiredate,salFromempWhereemp.depyno=10结果:en
10、amejo