数据库第三章作业

合集下载

国开作业数据库应用技术-第三章 本章自测35参考(含答案)

国开作业数据库应用技术-第三章 本章自测35参考(含答案)

题目:下列关于SQL Server中扩大数据库空间的说法,正确的是()。

选项A:只能扩大日志文件的空间,不能扩大数据文件的空间
选项B:在数据库空间未用满时不能进行扩大数据库空间的操作
选项C:日志文件和数据文件的空间都可以扩大
选项D:只能扩大数据文件的空间,不能扩大日志文件的空间
答案:日志文件和数据文件的空间都可以扩大
题目:下列关于SQL Server数据库组成的说法,正确的是()。

选项A:一个数据库可由仅一个数据文件和仅一个日志文件组成
选项B:一个数据库可由仅一个数据文件和多个日志文件组成
选项C:一个数据库可由多个数据文件和多个日志文件组成
选项D:一个数据库可由多个数据文件和仅一个日志文件组成
答案:一个数据库可由多个数据文件和多个日志文件组成
题目:在一台计算机上只能安装一个SQL Server默认实例。

选项A:对
选项B:错
答案:对
题目:SQL Server 2008最核心的服务是SSMS。

选项A:对
选项B:错
答案:错
题目:一个数据库必须包含次要数据文件,可以包含一个或多个次要数据文件。

选项A:对
选项B:错
答案:错
题目:主要数据文件的推荐扩展名是mdf。

选项A:对
选项B:错
答案:对
题目:删除数据库,只能删除数据文件,并不删除日志文件。

选项A:对
选项B:错
答案:错。

《数据库》第三章参考答案

《数据库》第三章参考答案

(1)检索 检索LIU老师所授课程的课程号、课程名。 老师所授课程的课程号、 检索 老师所授课程的课程号 课程名。
π CNO,CNAME(σTNAME =‘LIU’(C)) ,
(2) 检索年龄大于 岁的男学生的学号与姓名。 检索年龄大于23岁的男学生的学号与姓名 。 岁的男学生的学号与姓名
πsno,sname
[例 3.11]设有三个关系: 例 设有三个关系: 设有三个关系 学生关系: 学生关系 S(SNO,SNAME,AGE,SEX,SDEPT) ( , , , , ) 学习关系: 学习关系 SC(SNO,CNO,GRADE) ( , , ) 课程关系: 课程关系 C(CNO,CNAME,CDEPT,TNAME) ( , , , ) 试用关系代数表达式表示下列查询语句。 试用关系代数表达式表示下列查询语句。
(7)检索全部学生都选修的课程的课程号与 ) 课程名。 课程名。
πcno
(S))) )
,CNAME
(C
∞ ( πSNO,CNO(SC) , )
÷
π
SNO
(8)检索选修课程包含 )检索选修课程包含LIU老师所授 老师所授 课程的学生学号。 课程的学生学号。
π sno,CNO(SC)
÷πCNO(σTNAME =‘LIU’(C))
(σAGE>’23’ ∧ SEX=‘M’(s)) >
(3)检索学号为 学生所学课程的课程名与 )检索学号为S3学生所学课程的课程名与 任课老师名。 任课老师名。
πCNAME,TNAME(σSNO =‘S3’ ( sc∞c)) ,
( 4) 检索至少选修 ) 检索至少选修LIU老师所授课程中一门 老师所授课程中一门 课的女学生姓名。 课的女学生姓名。
πSNAME(σSEX=‘F’∧TNAME=‘LIU’ (s∞sc ∞c))

数据库第三章所有例题参考答案

数据库第三章所有例题参考答案

11级信管,保密,图档上机考试题目与参考答案3.3Simple Select Statements1.EXAMPLE 3.3.1find the aid values and names of agents that are based in New York. select aid, aname from agents where city=’New York’;2.EXAMPLE3.3.3Retrieve all pid values of parts for which orders are placed.select distinct pid from orders;3.EXAMPLE 3.3.4retrieve all customer-agent name pairs, (cname, aname), where the customer places an order through the agent.select distinct ame,agents.anamefrom customers,orders,agentswhere customers.cid=orders.cid and orders.aid=agents.aid;4.EXAMPLE 3.3.6all pairs of customers based in the same city.select c1.cid, c2.cidfrom customers c1, customers c2where c1.city = c2.city and c1.cid < c2.cid;5.EXAMPLE 3.3.7find pid values of products that have been ordered by at least twocustomers.select distinct x1.pidfrom orders x1, orders x2where x1.pid = x2.pid and x1.cid < x2.cid;6.EXAMPLE 3.3.8Get cid values of customers who order a product for which an order is also placed by agent a06.select distinct y.cidfrom orders x, orders ywhere y.pid = x,pid and x.aid = ‘a06’;3.4Subqueries7.EXAMPLE 3.4.1Get cid values of customers who place orders with agents in Duluth or Dallas.select distinct cid from orderswhere aid in (select aid from agentswhere city= ‘Duluth’ or city = ‘Dallas’)8.EXAMPLE 3.4.2to retrieve all information concerning agents based in Duluth or Dallas (very close to the Subquery in the previous example).select * from agentswhere city in (‘Duluth’, ‘Dallas’ );or select *from agentswhere city = ‘Duluth’ or city = ‘Dallas’;9.EXAMPLE 3.4.3to determine the names and discounts of all customers who place orders through agents in Duluth or Dallas.select distinct cname, discnt from customerswhere cid in (select cid from orders where aid in(select aid from agents where city in (‘Duluth’, ‘Dallas’ ))); 10.EXAMPLE 3.4.4to find the names of customers who order product p05.select distinct cname from customers, orderswhere customers.cid = orders.cid and orders.pid = ‘p05’or select disti nct cname from customers where ‘p05’ in(select pid from orders where cid = customers.cid);11.EXAMPLE 3.4.5Get the names of customers who order product p07 from agent a03. select distinct cname from customerswhere cid in (select cid from orders where pid = ‘p07’ and aid = ‘a03’) 12.EXAMPLE 3.4.6to retrieve ordno values for all orders placed by customers in Duluth through agents in New York.select ordno from orders x where exists(select * from customers c, agents awhere c.cid = x.cid and a.aid = x.aid and c.city = ‘Duluth’ anda.city=‘New York’);13.EXAMPLE 3.4.7find aid values of agents with a minimum percent commission.select aid from agents where percent = (select min(percent) from agents);14.EXAMPLE 3.4.8find all customers who have the same discount as that of any of the customers in Dallas or Boston.select cid, cname from customerswhere discnt = some (select discnt from customerswhere city = ‘Dallas’ or city = ‘Boston’);15.EXAMPLE 3.4.9Get cid values of customers with discnt smaller than those of any customers who live in Duluth.select cid from customerswhere discnt <all (select discnt from customerswhere city = ‘Duluth’);16.EXAMPLE 3.4.10Retrieve all customer names where the customer places an order through agent a05.select distinct ame from customers cwhere exists (select * from orders xwhere c.cid = x.cid and x.aid = ‘a05’);or select distinct ame from customers c, orders xwhere c.cid = x.cid and x.ai d = ‘a05’ ;17.EXAMPLE 3.4.11Get cid values of customers who order both products p01 and p07. select distinct cid from orders xwhere pid = ‘p01’ and exsits (select * from orderswhere cid = x.cid and pid = ‘p07’);orselect distinct x.cid from orders x, orders ywhere x.pid = ‘p01’ and x.cid = y.cid and y.pid = ‘p07’;18.EXAMPLE 3.4.12Retrieve all customer names where the customer does not place an order through agent a05.select distinct ame from customers cwhere not exists (select * from orders xwhere c.cid = x.cid and x.aid = ‘a05’);19.EXAMPLE 3.4.13retrieving all customer names where the customer does not place an order through agent a05, but using the two equivalent NOT IN and <>ALLpredicates in place of NOT EXISTS.select distinct ame from customers cwhere c.cid not in (select cid from orders where aid = ‘a05’);or select ame from customers cwhere c.cid <>all (select cid from orders where aid = ‘a05’);20.EXAMPLE 3.4.14Find cid values of customers who do not place any order through agent a03.select distinct cid from orders xwhere not exists (select * from orderswhere cid = x.cid and aid = ‘a03’);orselect cid from customers cwhere not exists (select * from orderswhere cid = c.cid and aid = ‘a03’);21.EXAMPLE 3.4.15Retrieve the city names containing customers who order product p01. select distinct city from customers where cid in(select cid from orders where pid = ‘p01’);or select distinct city from customers where cid =some(select cid from orders where pid = ‘p01’);or select distinct city from customers c where exsits(select * from orders where cid = c.cid and pid = ‘p01’);or select distinct city from customers c, orders xwhere x.cid = c.cid and x.pid = ‘p01’;or select distinct city from customers c where ‘p01’ in(select pid from orders where cid = c.cid);3.5UNION Operators and FOR ALL Conditions 22.EXAMPLE 3.5.1to create a list of cities where either a customer or an agent, or both, is based.select city from customersunion select city from agents;23.EXAMPLE 3.5.2Get the cid values of customers who place orders with all agents based in New York.select c.cid from customers cwhere not exsits(select * from agents awhere a.city = ‘New York’ and not exsits(select * from orders xwhere x.cid = c.cid and x.aid = a.aid));24.EXAMPLE 3.5.3Get the aid values of agents in New York or Duluth who place orders forall products costing more than a dollar.select aid from agents awhere (a.city = ‘New York’ or a.city = ‘Duluth’)and not exsits(select p.pid from products pwhere p.price > 1.00 and not exsits(select * from orders xwhere x.pid = p.pid and x.aid = a.aid));25.EXAMPLE 3.5.4Find aid values of agents who place orders for product p01 as well as for all products costing more than a dollar.select a.aid from agents a where a.aid in(select aid from orders where pid = ‘p01’)and not exsits (select p.pid from products pwhere p.price > 1.00 and not exsits (select * from orders xwhere x.pid = p.pid and x.aid = a.aid));or select distinct y.aid from orders ywhere y.pid = ‘p01’ and not exsits(select p.pid from products pwhere p.price > 1.00 and not exsits(select * from orders xwhere x.pid = p.pid and x.aid = y.aid));26.EXAMPLE 3.5.6Find pid values of products supplied to all customers in Duluth.select pid from products pwhere not exsits(select c.cid from customers cwhere c.city = ‘Duluth’and not exists(select * from orders xwhere x.pid = p.pid and x.cid = c.cid));3.7 Set Functions in SQL27.EXAMPLE 3.7.1determine the total dollar amount of all orders.select sum(dollars) as totaldollars from orders28.EXAMPLE 3.7.2To determine the total quantity of product p03 that has been ordered. select sum(qty) as TOTAL from orders where pid=’p03’29.EXAMPLE 3.7.4Get the number of cities where customers are based.select count(distinct city) from customers30.EXAMPLE 3.7.5List the cid values of alt customers who have a discount less than the maximum discount.select cid from customerswhere discnt < (select max(discnt) from customers)31.EXAMPLE 3.7.6Find products ordered by at least two customers.select p.pid from products pwhere 2 <=(select count(distinct cid) from orders where pid=p.pid)图档的学生的上机考查的考题到此为止___________________________________________________________ ___________________________________________________________ 信管,保密的学生上机考查还包括下面的题目32.EXAMPLE 3.7.7Add a row with specified values for columns cid, cname, and city (c007, Windix, Dallas, null)to the customers table.insert into customers(cid, cname, city)values (‘c007’, ‘Windix’, ‘Dallas’)33.EXAMPLE 3.7.9After inserting the row (c007, Windix, Dallas, null) to the customers table in Example 3.7.7, assume that we wish to find the average discount of all customers.select avg(discnt) from customers3.8 Groups of Rows in SQL34.EXAMPLE 3.8.1to calculate the total product quantity ordered of each individual product by each individual agent.select pid, aid, sum(qty) as TOTAL from ordersgroup by pid, aid35.EXAMPLE 3.8.2Print out the agent name and agent identification number, and the product name and product identification number, together with the total quantity each agent supplies of that product to customers c002 and c003.select aname, a.aid, pname, p.pid, sum(qty)from orders x, products p, agents awhere x.pid = p.pid and x.aid = a.aid and x.cid in (‘c002’, ‘c003’)group by a.aid, a.aname, p.pid, p.pname36.EXAMPLE 3.8.3Print out all product and agent IDs and the total quantity ordered of the product by the agent, when this quantity exceeds 1000.select pid, aid, sum(qty) as TOTAL from ordersgroup by pid, aidhaving sum(qty) > 100037.EXAMPLE 3.8.4Provide pid values of all products purchased by at least two customers. select distinct pid from ordersgroup by pidhaving count(distinct cid) >= 23.9 A Complete Description of SQL Select38.EXAMPLE 3.9.1List all customers, agents, and the dollar sales for pairs of customers and agents, and order the result from largest to smallest sales totals. Retain only those pairs for which the dollar amount is at least equal to 900.00. select ame, c.cid, a.aname, a.aid, sum(dollars) as casalesfrom customers c, orders o, agents awhere c.cid = o.cid, and a.aid = o.aidgroup by ame, c.cid, a.aname, a.aidhaving sum(o.dollars) >= 900.00order by casales desc39.EXAMPLE 3.9.2listed the cid values of all customers with a discount less than the maximum discount.select cid from customerswhere discnt < (select max(discnt) from customers)40.EXAMPLE 3.9.3Retrieve the maximum discount of all customers.select max(discnt) from customers;select distinct discnt from customers cwhere discnt >= all (select discnt from customers dwhere d.cid<>c.cid)41.EXAMPLE 3.9.4Retrieve all data about customers whose cname begins with the letter “A”.select * from customers where cname like ‘A%’42.EXAMPLE 3.9.5Retrieve cid values of customers whose cname does not have a third letter equal to “%”.select cid from customers where cname not like ‘__[%]’43.EXAMPLE 3.9.6Retrieve cid values of customers whose cname begins “Tip_” and has an arbitrary number of characters following.select cid from customers where cname like ‘TIP\[_]%’44.EXAMPLE 3.9.7Retrieve cid values of customers whose cname starts with the sequence “ab\”.select cid from customers where cname like ‘ab\%’3.10 Insert, Update, and Delete Statements 45.EXAMPLE 3.10.1Add a row with specified values to the orders table, setting the qty and dollars columns null.insert into orders (ordno, month, cid, aid, pid)values (1107, ‘aug’, ‘c006’, ‘a04’, ‘p01’)46.EXAMPLE 3.10.2Create a new table called swcusts of Southwestern customers, and insert into it all customers from Dallas and Austin.create table swcusts (cid char(4) not null,cname varchar(13),city varchar(20),discnt real);insert into swcustsselect * from customerswhere city in (‘Dallas’, ‘Austin’)47.EXAMPLE 3.10.3Give all agents in New York a 10% raise in the percent commission they earn on an order.update agents set percent = 1.1 * percent where city = ‘New York’48.EXAMPLE 3.10.4Give all customers who have total orders of more than $1000 a 10% increase in the discnt.update agents set percent = 1.1 * discntwhere cid in(select cid from orders group by cid having sum(dollars) > 1000) 49.EXAMPLE 3.10.6Delete all agents in New York.delete from agents where city = ‘New York’50.EXAMPLE 3.10.7Delete all agents who have total orders of less than $600.Delete from agents where aid in(select aid from ordersGroup by aidHaving sum(dollars)<600)51.EXAMPLE 3.11.2Retrieve the names of customers who order products costing $0.50. delete from agents where aid in(select aid from orders group by aid having sum(dollars)<600)(完)。

数据库第三章习题参考

数据库第三章习题参考

5.求至少用了供应商S1所供应的全部零件的工程号JNO。 即查找:不存在这样的零件y,供应商S1供应了y,而工程x为选用y。 Select distinct jno From spj z Where not exists (select * from spj x where sno=‘S1’ and not exists (select * from spj y where y.pno=x.pno and y.jno=z.jno));
习题三 第5题
1. 找出所有供应商的姓名及其所在城市。 Select sname, city from s; 2. 找出所有零件的名称、颜色、重量。 Select pname, color, weight from p; 3.找出使用供应商S1所供应零件的工程项目代码。 Select jno from spj where sno=‘S1’;
7. 找出没有使用天津产的零件的工程项目代码。 Select jno from j where not exists (Select * from spj where spj.jno=j.jno and sno in (Select sno from s where city=‘天津’) );
3.求供应工程J1零件为红色的供应商号码。 Select sno from spj, p Where spj.pno=p.pno and jno=‘J1’ and color=‘红’; 或: Select sno from spj Where jno =‘J1’ and pno in (Select pno from p Biblioteka where color=‘红’ );
6. 找出使用上海产的零件的工程项目名。 Select jname from j,spj,s where j.jno=spj.jno and spj.sno=s.sno and s.city=‘上海’; 或: Select jname from j where jno in (Select jno from spj, s where spj.sno=s.sno and s.city=‘上海’);

数据库第3章习题参考答案

数据库第3章习题参考答案

第3章习题解答1.选择题(1)表设计器的“允许空”单元格用于设置该字段是否可输入空值,实际上就是创建该字段的(D)约束。

A.主键B.外键C.NULL D.CHECK(2)下列关于表的叙述正确的是(C)。

A.只要用户表没有人使用,则可将其删除B.用户表可以隐藏C.系统表可以隐藏D.系统表可以删除(3)下列关于主关键字叙述正确的是( A )。

A.一个表可以没有主关键字B.只能将一个字段定义为主关键字C.如果一个表只有一个记录,则主关键字字段可以为空值D.都正确(4)下列关于关联叙述正确的是( C )。

A.可在两个表的不同数据类型的字段间创建关联B.可在两个表的不同数据类型的同名字段间创建关联C.可在两个表的相同数据类型的不同名称的字段间创建关联D.在创建关联时选择了级联更新相关的字段,则外键表中的字段值变化时,可自动修改主键表中的关联字段(5)CREATE TABLE语句(C )。

A.必须在数据表名称中指定表所属的数据库B.必须指明数据表的所有者C.指定的所有者和表名称组合起来在数据库中必须唯一D.省略数据表名称时,则自动创建一个本地临时表(6)删除表的语句是(A)。

A.Drop B.Alter C.Update D.Delete (7)数据完整性不包括(B )。

A.实体完整性B.列完整性C.域完整性D.用户自定义完整(8)下面关于Insert语句的说法正确的是(A )。

A.Insert一次只能插入一行的元组B.Insert只能插入不能修改C.Insert可以指定要插入到哪行D.Insert可以加Where条件(9)表数据的删除语句是( A )。

A.Delete B.Inser C.Update D.Alter (10)SQL数据定义语言中,表示外键约束的关键字是(B )。

A.Check B.Foreign Key C.Primary Key D.Unique2.填空题(1)数据通常存储在表中,表存储在数据库文件中,任何有相应权限的用户都可以对之进行操作。

3数据库基本操作习题与答案

3数据库基本操作习题与答案

第三章数据库基本操作一、选择题1. 如果需要给当前表增加一个字段,应使用的命令是________。

A) APPEND B) INSERTC) EDIT D) MODIFY STRU2. 设表文件及其索引已打开,为了确保指针定位在物理记录号为1的记录上,应该使用命令________。

A) SKIP 1 B) SKIP -1C) GO 1 D) GO TOP3. 要显示数据库中当前一条记录的内容,可使用命令________。

A) LIST B) BROWSEC) TYPE D) DISPLAY4. 在当前表中,查找第2个女同学的记录,应使用命令________。

A) LOCATE FOR 性别="女"B) LOCATE FOR 性别="女" NEXT 2C) LIST FOR 性别="女"CONTINUED) LOCATE FOR 性别="女"CONTINUE5. Visual FoxPro的数据库表之间可建立两种联系,它们是________。

A) 永久联系和临时联系B) 长期联系和短期联系C) 永久联系和短期联系D) 长期联系和临时联系6. 数据库表的索引中,字段值不能有重复的索引有________种。

A) 1 B) 2C) 3 D) 47. 建立表间临时关联的命令是________。

A) LET RELATION TO命令B) JOIN命令C) SET RELATION TO命令D) 以上都不是8. 通过关键字建立表间的临时关联的前提是________。

A) 父表必须索引并打开B) 子表必须索引并打开C) 两表必须索引并打开D) 两表都不必索引9. 查询设计器的“筛选”选项卡上,“插入”按钮的作用是________。

A) 用于增加查询输出字段B) 用于增加查询的表C) 用于增加查询去向D) 用于插入查询输出条件10. 在多工作区的操作中,如果选择了4,7,8号工作区并打开了相应的数据库,在命令窗口执行命令SELECT 0,其功能是________。

数据库系统原理第三章同步练习

数据库系统原理第三章同步练习

性。
8. 消除了非主属性对候选键局部依赖的关系模式, 9. 两个函数依赖集F和G等价的充分必要条件是
10. 消除了每一属性对候选键传递依赖的关系模
式称为 BCNF 模式
11. 一个关系模式属于 4NF ,它必定属于BCNF。
A. 互不相关的
B. 不可分解的
C. 长度可变的
D. 互相关联的
6. 假设关系模式R(A,B)属于3NF,下列说法( B )
是正确的
A. 它一定消除了插入和删除异常
B. 仍存在一定的插入和删除异常
C. 一定属于BCNF
D. A和C
7. 设有关系W(工号, 姓名, 工种, 定额), 将其规范
化到第三范式正确的答案是( C )
1NF变成了3NF
A. 局部函数依赖和传递函数依赖
B. 完全函数依赖和传递函数依赖
C. 完全函数依赖
D. 局部函数依赖
13. 下述说法正确的是( D )
A. 属于BCNF的关系模式不存在存储异常
B. 函数依赖可由属性值决定,不由语义决定
C. 超键就是候选键
D. 键是唯一能决定一个元组的属性或属性组
一、单项选择题
1. 当B属性函数依赖于A属性时,属性A与B的联
系是(B )
A. 一对多
C. 多对多
B. 多对一
C. 以上都不是
2. 关系模式R中的属性全部是主属性,则R的最高
范式必定是(B )
A. 2NF
B. 3NF
C. BCNF
D. 4NF
3. 在关系模式R(A,B,C,D)中,有函数依赖集F={
Z=U-X-Y,则 X →→Z
5. 若关系模式R已属于第一范式,且其中的每一

数据库第3章习题

数据库第3章习题

(一)选择题1.关系数据库管理系统应能实现的专门关系运算包括____。

A.排序、索引、统计B.选择、投影、连接C.关联、更新、排序D.显示、打印、制表2.在一个关系中如果有这样一个属性或属性组存在,它的值能唯一地标识关系中的每一个元组,称这个属性或属性组为____。

A.关键字B.数据项C.主属性D.主属性值3.同一个关系模型的任两个元组值____。

A.不能全同B.可全同C.必须全同D.以上都不是4.一个关系数据库文件中的各条记录____。

A.前后顺序不能任意颠倒,一定要按照输入的顺序排列B.前后顺序可以任意颠倒,不影响库中的数据关系C.前后顺序可以任意颠倒,但排列顺序不同,统计处理的结果就可能不同D.前后顺序不能任意颠倒,一定要按照关键字段值的顺序排列5.在关系代数的传统集合运算中,假定有关系R和S,运算结果为W。

如果W中的元组属于R,或者属于S,则W为____运算的结果。

如果W中的元组属于R而不属于S,则为____运算的结果。

如果W中的元组既属于R又属于S,则W为____运算的结果。

A.笛卡尔积B.并C.差D.交6.在关系代数的专门关系运算中,从表中取出满足条件的属性的操作称为____;从表中选取满足某种条件的元组的操作称为____;将两个关系中具有共同属性值的元组连接到一起构成新表的操作称为____。

A.选择B.投影C.连接D.扫描7.自然连接是构成新关系的有效方法。

一般情况下,当对关系R和S使用自然连接时,要求R和S含有一个或多个共有的____。

A.元组B.行C.记录D.属性8.等值连接与自然连接是____。

A.相同的B.不同的9.如图所示的关系R,经操作ΠA,B(σB=b(R))(Π为“投影”运算符,σ“选择”运算符)的运算结果是____。

D10.设有属性A,B,C,D,以下表示中不是关系的是____。

A.R(A)B.R(A,B,C,D)C.R(A×B×C×D)D.R(A,B)11.关系运算中花费时间可能最长的运算是____。

【精选】数据库第三章课后习题

【精选】数据库第三章课后习题
order by grade
• 14、 • (1)GRANT SELECT ON 职工,部门TO 王明 • (2) GRANT INSERT,DELETE ON 职工,部门TO
李勇
• (3) GRANT SELECT ON 职工WHEN USER() = NAME TO ALL
• (4) GRANT SELECT,UPDATE(工资) ON 职工 TO 刘星
• 7、视图的优点 • 视图能够简化用户的操作 • 视图使用户能以多种角度看待同一数据 • 视图对重构数据库提供了一定程度的逻辑
独立性; • 视图能够对机密数据提供安全保护。
• 8、所有的视图是否都可以更新?
• 不是。视图是不实际存储数据的虚表,因 此对视图的更新,最终要转换为对基本表 的更新。因为有些视图的更新不能惟一有 意义地转换成对相应基本表的更新,所以 ,并不是所有的视图都是可更新的。
SPJ TO 李天明;
• 13、 • (1)INSERT INTO SC(Sno,Cno,Grade)
VALUES("2000012", "1128", NULL); • (2)SELECT Sno,Cno
FROM SC
WHERE Grade IS NULL;
• (3)SELECT cname,grade FROM course,Sc WHERE o=o AND cname="英语"
• (1) SELECT DIST PNO,QTY FROM SPQ
• (2) SELECT DIST * FROM SPQ WHERE SNO="S1‘
• 12、 • (1)GRANT INSERT
ON TABLE S TO 张勇

数据库原理第三章练习

数据库原理第三章练习

第三章SQL语言一、选择题:1、SQL语言是的语言,易学习。

A.过程化 B.非过程化C.格式化 D.导航式2、SQL语言是语言。

A.层次数据库 B.网络数据库C.关系数据库 D.非数据库3、SQL语言具有的功能。

2、关系规范化,数据操纵,数据控制B.数据定义,数据操纵,数据控制C.数据定义,关系规范化,数据控制D.数据定义,关系规范化,数据操纵4、SQL语言具有两种使用方式,分别称为交互式SQL和。

A.提示式SQL B.多用户SQLC.嵌入式SQL D.解释式SQL5、SQL语言中,实现数据检索的语句是。

A.SELECT B.INSERTC.UPDATE D.DELETE6、下列SQL语句中,修改表结构的是。

A.ALTER B.CREATEC.UPDATE D.DELETE7、SQL中,与“NOT IN”等价的操作符是。

A.=SOME B.<>SOMEC.=ALL D.<>ALL8、假设有三个基本表:学生表S、课程表C、学生选课表SC,它们的结构如下:S(S#,SN,SEX,AGE,DEPT)C(C#,CN)SC(S#,C#,GRADE)检索所有比“王华”年龄大的学生姓名、年龄和性别。

正确的SQL语句是。

A.SELECT SN,AGE,SEXFROM SWHERE AGE>(SELECT AGE FROM SWHERE SN=”王华”)B.SELECT SN,AGE,SEXFROM SWHERE SN=”王华”C.SELECT SN,AGE,SEXFROM SWHERE AGE>(SELECT AGEWHERE SN=”王华”)D.SELECT SN,AGE,SEXFROM SWHERE AGE>王华.AGE9、检索选修课程”C2”的学生中成绩最高的学生的学号。

正确的SELECT语句是。

A.SELECT S#FROM SCWHERE C#=”C2” AND GRADE>=(SELECT GRADE FROM SCWHERE C#= “C2”)B.SELECT S#FROM SCWHERE C#=”C2” AND GRADE IN(SELECT GRADE FROM SCWHERE C#= “C2”)C.SELECT S#FROM SCWHERE C#=”C2” AND GRADE NOT IN(SELECT GRADE FROM SCWHERE C#= “C2”)D.SELECT S#FROM SCWHERE C#=”C2” AND GRADE>=ALL(SELECT GRADE FROM SCWHERE C#= “C2”)10、检索学生姓名及其所选修课程的课程号和成绩。

数据库第三章习题参考答案范文大全

数据库第三章习题参考答案范文大全

数据库第三章习题参考答案范文大全第一篇:数据库第三章习题参考答案3-2 对于教务管理数据库的三个基本表S(SNO,SNAME, SEX, AGE,SDEPT) SC(SNO,CNO,GRADE)C(CNO,CNAME,CDEPT,TNAME) 试用SQL的查询语句表达下列查询:⑴ 检索LIU老师所授课程的课程号和课程名。

⑵ 检索年龄大于23岁的男学生的学号和姓名。

⑶ 检索学号为200915146的学生所学课程的课程名和任课教师名。

⑷ 检索至少选修LIU老师所授课程中一门课程的女学生姓名。

⑸ 检索WANG同学不学的课程的课程号。

⑹ 检索至少选修两门课程的学生学号。

⑺ 检索全部学生都选修的课程的课程号与课程名。

⑻ 检索选修课程包含LIU老师所授课程的学生学号。

解:⑴ SELECT C#,CNAME FROM C WHERE TEACHER=’LIU’; ⑵ SELECT S#,SNAME FROM S WHERE AGE>23 AND SEX=’M’; ⑶ SELECT CNAME,TEACHER FROM SC,C WHERE SC.C#=C.C# AND S#=’200915146’ ⑷ SELECT SNAME (连接查询方式) FROM S,SC,C WHERE S.S#=SC.S# AND SC.C#=C.C# AND TEACHER=’LIU’;或:SELECT SNAME (嵌套查询方式) FROM S WHERE SEX=’F’AND S# IN (SELECT S# FROM SC WHERE C# IN (SELECT C# FROM C WHERE TEACHER=’LIU’)) 或:SELECT SNAME (存在量词方式)SEX=’F’ AND FROM S WHERE SEX=’F’ AND EXISTS(SELECT* FROM SC WHERE SC.S#=S.S# AND EXISTS(SELECT * FROM C WHERE C.C#=SC.C# AND TEACHER=’LIU’)) ⑸ SELECT C# FROM C WHERE NOT EXISTS(SELECT * FROM S,SC WHERE S.S#=SC.S# AND SC.C#=C.C# AND SNAME=’WANG)); ⑹ SELECT DISTINCT X.S# FROM SC AS X,SC AS Y WHERE X.S#=Y.S# AND X.C#!=Y.C#; ⑺ SELECT C#.CNAME FROM C WHERE NOT EXISTS (SELECT * FROM S WHERE NOT EXISTS (SELECT * FROM SC WHERE S#=S.S# AND C#=C.C#)); ⑻ SELECT DISTINCT S# FROM SC AS X WHERE NOT EXISTIS (SELECT * FROM C WHERE TEACHER=’LIU’ AND NOT EXISTS (SELECT * FROM SC AS Y WHERE Y.S#=X.S# AND Y.C#=C.C#)); 3-3 试用SQL查询语句表达下列对3.2题中教务管理数据库的三个基本表S、SC、C查询:⑴ 统计有学生选修的课程门数。

数据库作业第三章习题答案

数据库作业第三章习题答案

数据库作业第三章习题答案数据库作业第三章习题答案数据库作业是数据库课程中非常重要的一部分,通过完成作业可以帮助学生巩固和加深对数据库知识的理解和应用。

第三章习题主要涉及数据库设计和查询语言的使用。

在本篇文章中,我们将回答第三章习题,并探讨一些相关的概念和技巧。

1. 设计一个关系模式,用于存储学生的基本信息,包括学生编号、姓名、性别、年龄和专业。

请给出该关系模式的定义。

答案:学生(学生编号,姓名,性别,年龄,专业)2. 设计一个关系模式,用于存储课程的信息,包括课程编号、课程名称和学分。

请给出该关系模式的定义。

答案:课程(课程编号,课程名称,学分)3. 设计一个关系模式,用于存储学生选课的信息,包括学生编号、课程编号和成绩。

请给出该关系模式的定义。

答案:选课(学生编号,课程编号,成绩)4. 编写一个SQL查询语句,查询学生的姓名和年龄。

答案:SELECT 姓名, 年龄 FROM 学生;5. 编写一个SQL查询语句,查询选修了某门课程的学生的姓名和成绩。

答案:SELECT 学生.姓名, 选课.成绩FROM 学生, 选课WHERE 学生.学生编号 = 选课.学生编号AND 选课.课程编号 = '某门课程编号';6. 编写一个SQL查询语句,查询某个学生的选课情况,包括课程名称和成绩。

答案:SELECT 课程.课程名称, 选课.成绩FROM 课程, 选课WHERE 课程.课程编号 = 选课.课程编号AND 选课.学生编号 = '某个学生编号';通过以上习题的回答,我们可以看到数据库设计和查询语言的基本应用。

关系模式的定义是数据库设计的基础,它描述了数据表的结构和属性。

在查询语言的使用中,我们可以通过SELECT语句来检索和过滤数据,通过WHERE子句来指定查询条件。

除了上述习题的答案,我们还可以进一步探讨数据库设计的一些原则和技巧。

例如,为了提高数据库的性能和可扩展性,我们可以使用索引来加快数据的检索速度。

数据库系统概论第三章课后作业

数据库系统概论第三章课后作业

第三章作业参考答案3.用SQL 语句建立第二章习题5中的4个表。

CREATE TABLE S(SNO CHAR(3)primary key,SNAME CHAR(10)not null,STATUS CHAR(2),CITY CHAR(10));CREATE TABLE P(PNO CHAR(3)primary key,PNAME CHAR(10),COLOR CHAR(4),WEIGHT INT);CREATE TABLE J(JNO CHAR(3)primary key,JNAME CHAR(10),CITY CHAR(10));CREATE TABLE SPJ(SNO CHAR(3),PNO CHAR(3),JNO CHAR(3),QTY INTPrimary key(sno,pno,jno));4.针对上题中建立的4个表试用SQL 语言完成第二章习题5中的查询。

(1)求供应工程J1零件的供应商号码SNO;关系代数:SELECT SNOFROM SPJWHERE JNO =‘J1’;(2)求供应工程J1零件P1的供应商号码SNO;关系代数:SELECT SNOFROM SPJWHERE JNO =‘J1’AND PNO =‘P1’;(3)求供应工程J1零件为红色的供应商号码SNO;关系代数:FROM SPJWHERE JNO =‘J1’AND PNO IN(SELECT PNOFROM PWHERE COLOR =‘红’);或者是SELECT SNOFROM SPJ,PWHERE JNO =‘J1’AND SPJ.PNO = P.PNOAND COLOR =‘红’;(4)求没有使用天津供应商生产的红色零件的工程号JNO;注意:从J表入手,以包含那些尚未使用任何零件的工程号。

关系代数:SELECT JNOFROM JWHERE NOT EXISTSFROM SPJWHERE SPJ.JNO = J.JNOAND SNO IN(SELECT SNOFROM SWHERE CITY =’天津’)AND PNO IN(SELECT PNOFROM PWHERE COLOR =’红’));或者SELECT JNOFROM JWHERE NOT EXISTS(SELECT *FROM SPJ,S,PWHERE SPJ.JNO = J.JNOAND SPJ.SNO = S.SNOAND SPJ.PNO = P.PNOAND S.CITY =‘天津’AND P.COLOR =‘红’);(5)求至少用了供应商S1所供应的全部零件的工程号JNO(类似于《概论》P113例44)。

数据库第3章习题参考答案

数据库第3章习题参考答案

第3章习题解答1.选择题(1)表设计器的“允许空”单元格用于设置该字段是否可输入空值,实际上就是创建该字段的(D)约束。

A.主键B.外键C.NULL D.CHECK (2)下列关于表的叙述正确的是(C)。

A.只要用户表没有人使用,则可将其删除B.用户表可以隐藏C.系统表可以隐藏D.系统表可以删除(3)下列关于主关键字叙述正确的是(A )。

A.一个表可以没有主关键字B.只能将一个字段定义为主关键字C.如果一个表只有一个记录,则主关键字字段可以为空值D.都正确(4)下列关于关联叙述正确的是( C )。

A.可在两个表的不同数据类型的字段间创建关联B.可在两个表的不同数据类型的同名字段间创建关联C.可在两个表的相同数据类型的不同名称的字段间创建关联D.在创建关联时选择了级联更新相关的字段,则外键表中的字段值变化时,可自动修改主键表中的关联字段(5)CREATE TABLE语句(C )。

A.必须在数据表名称中指定表所属的数据库B.必须指明数据表的所有者C.指定的所有者和表名称组合起来在数据库中必须唯一D.省略数据表名称时,则自动创建一个本地临时表(6)删除表的语句是(A)。

A.Drop B.Alter C.Update D.Delete(7)数据完整性不包括(B )。

A.实体完整性B.列完整性C.域完整性D.用户自定义完整(8)下面关于Insert语句的说法正确的是(A )。

A.Insert一次只能插入一行的元组B.Insert只能插入不能修改C.Insert可以指定要插入到哪行D.Insert可以加Where条件(9)表数据的删除语句是( A )。

A.Delete B.Inser C.Update D.Alter(10)SQL数据定义语言中,表示外键约束的关键字是(B )。

A.Check B.Foreign Key C.Primary Key D.Unique 2.填空题(1)数据通常存储在表中,表存储在数据库文件中,任何有相应权限的用户都可以对之进行操作。

数据库第三章课后习题答案

数据库第三章课后习题答案

第三章课后习题3-7(1) delete from sWhere placeofb=’上海’;(2)delete from scWhere s# in (select s#from swhere sname=’李建平’);(3)delete form sWhere s# in(select s#from scwhere grade is null);3-8(1)update scSet grade=61Where grade<60 and c# in(select c#from cwhere cname=’计算机网络’);(2)update scSet grade=grade*1.05Where grade<(select avg(grade)From scWhere c# in(select c#From cWhere cname=’数据结构’)) andC# in(select c#From cWhere cname=’数据结构’);3-10(1)create view grade_tAsSelect s.s#,sname,c.c#,cname,classh,grade,t.t#,tnameFrom s,c,t,sc,teachWhere s.s#=sc.s# and c.c#=sc.c# and sc.c#=teach.c# and teach.t#=t.t#;(2)create view teach_lAsSelect t.t#,tname,c#,cname,classh,avg(grade) as avg_gradeFrom t,c,sc,teachWhere t.t#=teach.t# and teach.c#=sc.c# and sc.c#=c.c#Group by t.t#;3-11 select s#,snameFrom sWhere ssex=’男’;3-12 select s#,snameFrom sWhere sbirthin>’1981-1-1’ and sex=’女’;3-13 select s#,ssex,scode#From sWhere s# in (select s#From scWhere c# in (select c#From cWhere cname=’操作系统’));3-14 select s#,sname,scode#From sWhere s# in(select s#From scWhere c# in(select c#From teachWhere t# in(select t#From tWhere tname=’刘少华’)));3-15 select s#,snameFrom sWhere not exists(select *From cWhere not exists(select *From scWhere sc.s#=s.s# andc.c#=sc.c#));3-16 select c#,classh,tnameFrom c,teach,t,s,scWhere c.c#=sc.c# and sc.c#=teach.c# and teach.t#=t.t# and sc.s#=s.s# and s.sname=’王丽丽’;3-17 select c#,classhFrom cWhere c# in(select c#From teachWhere t# in(select t#From tWhere tname=’刘少华’));3-18 select tnameFrom tWhere t# in(select t#From teach);3-19 select s#,sname,sbirthinFrom sWhere scode# in(select scode#From ssWhere ssname=’计算机应用技术’) order by sbirthin;3-20 select s#,snameFrom sWhere s# in(select s#From scWhere c# in(select c#From cWhere cname=’计算机网络’)); 3-21 select s#,snameFrom sWhere s# in(select s#From scWhere c# in(select c#From cWhere cname=’计算机网络’));Intersectselect s#,snameFrom sWhere s# in(select s#From scWhere c# in(select c#From cWhere cname=’信息安全技术’)); 3-22 select s#,sname,ssnameFrom s,ssWhere s.scode#=ss.scode# and s# not in(select s#From scWhere c# in(select c#From cWhere cname=’计算机网络’));3-23 select c#,cnameFrom cWhere c# in(select c#From scGroup by c#Having count(*)>=5);。

数据库运维第三章自测答案

数据库运维第三章自测答案

数据库运维第三章自测答案1. ()是 SQL Server里保存所有的临时表和临时存储过程。

[单选题] *A master数据库B tempdb数据库(正确答案)C model数据库D msdb数据库2. 关于JDBC PreparedStatement,下面说法错误的是 [单选题] *A 数据库B 高级语言C OSD 数据库应用系统和开发工具(正确答案)3. 关于JDBC PreparedStatement,下面说法错误的是 [单选题] *A 可以用来进行动态查询B 通过预编译和缓存机制提升了执行的效率C 不能直接用它来执行in条件语句,但可以动态生成PreparedStatement,一样能享受PreparedStatement缓冲带来的好处(正确答案)D 有助于防止SQL注入,因为它会自动对特殊字符转义4. 在通常情况下,下面的关系中不可以作为关系数据库的关系是 [单选题] *A R1(学生号,学生名,性别)B R2(学生号,学生名,班级号)C R3(学生号,学生名,宿舍号)D R4(学生号,学生名,简历)(正确答案)5. 为数据表创建索引的目的是? [单选题] *A 提高查询的检索性能(正确答案)B 创建唯一索引C 创建主键D 归类6. 下述SQL语句中,起修改表中数据作用的命令动词是 [单选题] *A ALTERB CREATEC UPDATED INSERT(正确答案)7. SQL的数据更新不包括下列哪个命令 [单选题] *A INSERTB UPDATEC DELETED CREATE(正确答案)8. 以下不属于事务的特性的是 [单选题] *A 隔离性B 原子性C 可用性(正确答案)D 一致性E 持久性9. MODIFY STRUCTURE 命令的功能是: [单选题] *A 修改记录值A 修改记录值B 修改表结构C 修改数据库结D 修改数据库或表结构(正确答案)C 修改数据库结D 修改数据库或表结构10. ()使用户可以看见和使用的局部数据的逻辑结构和特征的描述。

数据库习题第三章 习题

数据库习题第三章 习题

CH3关系数据库标准语言SQL一、选择题1、SQL属于()数据库语言A、关系型B、网状型C、层次型D、面向对象型2、SQL中创建基本表应使用()语句A、CREATE INDEXB、CREATE TABLEC、CREATE VIEWD、CREATE DATEBASE3、SQL中创建视图应使用()语句A、CREATE SHCEMAB、CREATE TABLEC、CREATE VIEWD、CREATE DATEBASE4、关系代数中的Π运算对应SELECT语句中的()子句A、SELECTB、FROMC、WHERED、GROUP BY5、关系代数中的σ运算对应SELECT语句中的()子句A、SELECTB、FROMC、WHERED、GROUP BY6、WHERE子句的条件表达式中,可以匹配0个到多个字符的通配是()A、*B、%C、_D、?7、WHERE子句的条件表达式中,可以匹配单个字符的通配是()A、*B、%C、_D、?8、SELECT语句中与HA VING子句同时使用的是()子句A、ORDER BYB、WHEREC、GROUP BYD、无需配合9、与WHERE G BETWEEN 60 AND 100 语句等价的子句是()A、WHERE G>60 AND G<100B、WHERE G>=60 AND G<100C、WHERE G>60 AND G<=100D、WHERE G>=60 AND G<=10010、若用如下的SQL语句创建一个表student:CREATE TABLE student ( NO CHAR(4) NOT NULL,NAME CHAR(8) NOT NULL,SEX CHAR (2),AGE INT)可以插入到student表中的是()A、(‘1031’,‘刘华’,男,23)B、(‘1031’,‘刘华’,NULL,NULL)C、(NULL,‘刘华’,‘男’,‘23’)D、(‘1031’,NULL,‘男’,23)11、SQL语言支持建立聚簇索引,这样可以提高查询效率,但是,并非所有属性列都适宜建立聚簇索引,下面()属性列不适宜建立聚簇索引。

数据库第三章部分习题答案

数据库第三章部分习题答案

3.2 对于教学数据库的三个基本表S(S#,SNAME,AGE,SEX)SC(S#,C#,GRADE)C(C#,CNAME,TEACHER)试用SQL的查询语句表达下列查询:3.2.1检索年龄小于17岁的女学生的学号和姓名select s#,sname from Swhere age<17 and sex=F;3.2.2检索男生所学课程的课程号和课程名select c#,cname from Cwhere c# in (select distinct c#from SCwhere s# in (select s# from S where sex=M)) 3.2.3检索男生所学课程的任课老师的工号和姓名select t#,tname from Twhere t# in(select distinct t#from Cwhere c# in(select distinct c#from SCwhere s# in(select s#from Swhere sex=1)));3.2.4检索至少选修两门课程的学生的学号select s#from SCgroup by s#having count(c#)>=2;3.2.5检索至少有学号为S2和S4所学的课程和课程名select c#,cnamefrom Cwhere c# in((select c#from sc where s#='S2')intersect(select c# from sc where s#='S4') );3.2.6检索‘WANG’同学不学的课程号select c# from cexcept(select distinct c#from scwhere s# =(select s# from s where sname='WANG'));3.2.7检索全部学生都选修的课程号和课程名select c#,cnamefrom cwhere not exists(select s#from swhere c.c# not in (select c# from sc where sc.s#=s.s# ));3.2.8检索选修课程包含'LIU'老师所授课程的全部课程的学生的学号和姓名select s#,snamefrom swhere not exists((select c#from cwhere t#=(select t#from twhere tname='LIU')) except(select c# from sc where sc.s#=s.s#) );3.4 设有两个基本表R(A,B,C)和S(A,B,C),试用SQL查询语句表达下列关系代数表达式:① R∪S ② R∩S ③ R-S ④ R×S ⑤πA,B(R) πB,C(S)⑥π1,6(σ3=4(R×S)⑦π1,2,3(S)⑧R÷πC(S)解:①(SELECT * FROM R)UNION(SELECT * FROM S);②(SELECT * FROM R)INTERSECT(SELECT * FROM S);③(SELECT * FROM R)MINUS(SELECT * FROM S);④SELECT *FROM R, S;⑤SELECT R.A, R.B, S.CFROM R, SWHERE R.B=S.B;⑥SELECT R.A, S.CFROM R, SWHERE R.C=S.A;⑦SELECT R.* (R.*表示R中全部属性)FROM R, SWHERE R.C=S.C;⑧R÷πC(S)的元组表达式如下:{ t |(∃u)(∀v)(∃w)(R(u)∧S(v)∧R(w)∧w[1]=u[1] ∧w[2]=u[2] ∧w[3]=v[3] ∧t[1]=u[1] ∧t[2]=u[2])}据此,可写出SELECT语句:SELECT A, BFROM R RXWHERE NOT EXISTS( SELECT *FROM SWHERE NOT EXISTS( SELECT *FROM R RYWHERE RY.A=RX.A AND RY.B=RX.B ANDRY.C=S.C));3.6 试叙述SQL语言的关系代数特点和元组演算特点。

王珊数据库第三章课后题第四题

王珊数据库第三章课后题第四题

王珊数据库第三章课后题第四题这道题其实挺有意思的,咱们今天就来聊聊数据库里的一些小知识,别紧张,不用什么高深的术语。

就拿这个“数据库”来说,实际上它就是个大仓库,里面存放了各种信息。

你可以把它想成一个庞大的文件夹,里面的资料五花八门。

咱们要做的,就是搞清楚这个仓库的具体情况,知道它是怎么运作的,如何管理这些琳琅满目的信息的。

说到这,可能有的朋友脑袋已经开始晕了,别急,咱们慢慢理。

得先弄清楚题目中说的“关系模型”。

这其实就像是一张张有关系的表格,每一张表格里放着不同类型的数据,比如学生信息表、课程表、成绩表这些。

如果你是个学生,关系模型可能对你来说比较亲切,因为它就像班级里的座位安排表,每个人都有固定的位置。

数据就像同学们,每个数据都有自己明确的身份、属性,明明白白的。

有了这种模型,咱们就能清晰地找到需要的数据,像找人一样直接。

然后,咱们还得了解“键”是啥。

是不是觉得这就更复杂了,别急,咱们慢慢说。

键其实就是用来标识每一行数据的独一无二的标签,比如你自己的学号,学号是唯一的,不可能两个学生有相同的学号对吧?这个学号就是“主键”。

有了这个主键,每个学生的数据都可以精准定位,不会乱套。

主键就像是一个超级身份证,谁都不能和你重复。

有了这个,表格里所有数据都不至于乱成一锅粥。

除了主键,还有“外键”这个东西,外键有点像是表格之间的桥梁。

比如学生表和成绩表,成绩表上可能就会有学生学号这一项,这个学号是外键,它关联着学生表的数据。

就像你拿着班级成绩单上的名字去找这个人的详细信息,外键就是这个桥梁,保证两个表格之间能顺利对接,不会跑偏。

想象一下,如果没有外键,成绩表里的数据就像是天上掉下来的,不知道该找谁确认。

这时候,数据的关系就断了,啥都做不成了。

我们得聊聊“完整性约束”。

听起来像是个学术名词,其实就是在说如何保证咱们存储的数据是有意义的,准确的。

就像你写作业,老师要求你写清楚名字、班级、日期,这就是“约束”,目的是为了让你交作业时不出乱子。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

班级:软件工程2班姓名:方添翼学号:20125515233.1A.select * from course where dept_name='Comp. Sci.'and credits=3B.select distinct student.IDfrom (student join takes using(ID))join(instructor join teaches using(ID))using(course_id,sec_id,semester,year)where ='Einstein'C.select max(salary)from instructorD.select from instructor a where salary=(selectmax(salary)from instructor)E.select course_id,sec_id,count(ID)from section natural join takeswhere semester='Autumn'and year=2009group by course_id,sec_id;F.select max(a)from(select count(id)as afrom takes natural join sectionwhere semester='Autumn'and year=2009group by course_id,sec_id)G.3.2A.(select sum(credits*points)from(takes natural join course)natural join grade pointswhere ID='12345')B.select sum(credits*points)/sum(credits)as GPAfrom(takes natural join course)natural join grade_pointswhere id='12345'C.select id,sum(credits*points)/sum(credits)as GPAfrom(takes natural join course)natural join grade_pointsgroup by id3.3A.update instructorset salary=salary*1.1where dept_name='Comp.Sci'B.delete from coursewhere course_id not in(select course_id from section)C.insert into instructorselect ID,name,dept_name,10000from studentwhere tot_cred>1003.4A.select count(distinct name)from accident as a,participated as b,person as cwhere a.report_number=b.report_numberand b.driver_id=c.driver_idand data between'2009-00-00'and'2009-12-31'B.insert into accidentvalues(1234,'2014-01-01','xiangtan')insert into participatedselect b.driver_id,c.licence,1234,5000from person a,owns b,car cwhere ='jake'and a.driver_id=b.driver_id andb.license=c.license and c.model='joe'C.delete from carwhere model='Mazda'and license in(select licensefrom person a,owns bwhere a.driver_id=b.driver_id and ='john smith')3.5A.select idcasewhen score<40then'F'when score<60then'C'when score<80then'B'else'A'endfrom marksB.witn grades as(select id,casewhen score<40then'F'when score<60then'C'when score<80then'B'else'A'end as gradefrom marks)select grade,count(id)from gradesgroup by grade3.6select dept_namefrom departmentwhere lower(dept_name)like'%sci%'3.8a.(select customer_namefrom depositor)except(select customer_namefrom borrower)B.select F.customer_namefrom customer F join customer T using(customer_street,customer_city)where T.customer_name='Smith'C.select brance_namefrom customer natural join account natural join depositorwhere customer_name='Harrison'3.9A.select e.employee_name,cityfrom employee e,wroks wwhere pany_name='First Bnak Corporation'andw.employee_name=e.emloyee_nameB.select * from employeeWhere employee_name in(select employee_nameFrom wroksWhere company_name='First Bnak Corporation' and salary>10000) C.select employee_nameFrom employeeWhere employee_name not in(select employee_nameFrom wroksWhere company_name='First Bnak Corporation')D.select employee_nameFrom worksWhere salary>all(select salaryFrom wroksWhere company_name=’Small Bank Corporation’)E.select pany_nameFrom company sWhere not exists ((select cityFrom companyWhere company_name=’Small Bank Corporation’) Except(select cityFrom company tWhere pany_name=pany))F.select company_namefrom worksgroup by company_namehaving count(distinct employee_name)>=all(select count(distinct employee_name)from wroksGroup by company_name)G.select company_namefrom worksgroup by company_namehaving avg(salary)>(select avg(salary)from wrokswhere company_name='First Bank Corporation')3.10A.update employeeset city='Newton'where person_name='Jones'B.update wroks Tset T.salary=T.salary*(casewhen(T.salary>10000)then 1.03else 1.1)where T.employee_name in(select manager_namefrom manager)and pany_name='First Bank Corporation’3.11A.select distinct from student b ,takes c,course dwhere b.id=c.id and C.COURSE_ID=D.COURSE_IDand D.TITLE='Comp.Sci.';B.select distinct id,namefrom student natural join takeswhere year>2008;C.select max(salary)from instructorgroup by dept_name;D.select max(max_sal)from(select max(salary) max_salfrom instructorgroup by dept_name);3.12A.insert into course(course_id,title,credits,dept_name)values('CS-001','Weekly Seminar',0,null);B.insert into takes(course_id ,year,sec_id)values('CS-001','2009',1)C.insert into takesselect id,dept_name;from studentwhere dept_name='Comp.Sci.';D.delete from takeswhere course_id='CS-001'and name in(select namefrom studentwhere name='Chavez')E.delete from coursewhere course_id='CS-001';F.delete from takeswhere course_id in(select course_idfrom coursewhere low(title)like'%database')3.14A.select count(*)from accident a,participated b,person cwhere a.report_number=b.report_number and b.drive_id =c.drive_id and ='John Smith';B.update participatedset damage_amountwhere report_number='AR2197'and drive_id ='AABB2000';3.15A.select customer_namefrom customerwhere not exists((select branch_namefrom branch)minus(select T.branch_namefrom account_numberwhere t.branch_name = s.branch_name)B.select sum(amount)from loan;C.select branch_namefrom accountwhere balance >some in(select balancefrom accountwhere branch_name='Brooklyn');3.16A.select employee_namefrom workswhere company_name ='First Bank Corporation'B.select namefrom employee natural join works a,employee natural join works b where pany_name=pany_name and a.street = b.street;C.select namefrom employee natural join managers a,employeewhere a.manager_name=b.employee_name and a.street =b.streetD.select namefrom works awhere pany=pany and salary >(select avg(salary)from works bgroup by company);E.select company_namefrom(select avg(salary) avg_salaryfrom worksgroup by company_name)where avg_sal=(select min(salary) avg_salary from worksgroup by company_name);3.17A.update from worksset salary =salary*1.1where company_name='First Bank Corporation'B.update from worksset salary =salary*1.1where company_name='First Bank Corporation'and employee_name in(select manager_namefrom manager)C.delete from workswhere company_name ='Small Bank Corporation'3.21A.select namefrom borrowed a,member b, book cwhere a.memb_no =b.mem_no and a.isbn =c.isbn and c.publisher ='McGraw-Hill';B.select all namefrom borrowed a,member b, book cwhere a.memb_no =b.mem_no and a.isbn =c.isbn and c.publisher ='McGraw-Hill';C.select namefrom member a, borrowed bwhere count(memb_no)>5group by nameD.insert from borrowedvalues(0);where memb_no in(select memb_nofrom borrowed)select avg(isbn)from borrowed3.23select course_id,semester ,year,sec_id ,avg(tot_cred) from takes natural join studentwhere year=2009group by course_id,semester,year,sec_idhaving count(id)>=2order by course_id;select course_id,semester ,year,sec_id ,avg(tot_cred) from takes natural join student natural join sectionwhere year=2009group by course_id,semester,year,sec_idhaving count(id)>=2order by course_id;3.24select dept_namefrom(select dept_name,sum(salary)from instructorgroup by dept_name) depta_total,(select avg(values)from dept_total) dept_total_avgwhere dept_total.values>=dept_total_avg.values;。

相关文档
最新文档