数据库第三章作业
- 格式:doc
- 大小:46.00 KB
- 文档页数:5
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)(完)。
第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)数据通常存储在表中,表存储在数据库文件中,任何有相应权限的用户都可以对之进行操作。
第三章数据库基本操作一、选择题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,其功能是________。
(一)选择题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.关系运算中花费时间可能最长的运算是____。
三、设计题1.(1)SELECT BAuth FROM Book, PublishWHERE Book.PNo= Publish.PNo AND BName=’操作系统’ AND PName=’高等教育出版社’(2)查找为作者“张欣”出版全部“小说”类图书的出版社的电话。
SELECT PTel FROM Book, PublishWHERE Book.PNo= Publish.PNo AND BType =’小说’ AND BAuth=’张欣’(3)查询“电子工业出版社”出版的“计算机”类图书的价格,同时输出出版社名称及图书类别。
SELECT BPrice, PName, BType FROM Book, PublishWHERE Book.PNo= Publish.PNo AND PName =’电子工业出版社’ AND BType =’计算机’(4)查找比“人民邮电出版社”出版的“高等数学”价格低的同名书的有关信息。
SELECT * FROM BookWHERE BName =’高等数学’AND BPrice<ANY(SELECT BPrice FROM Book,PublishWHERE Book.PNo= Publish.PNo AND PName =’人民邮电出版社’ AND BName =’高等数学’)AND PName <>’人民邮电出版社’(5)查找书名中有“计算机”一词的图书的书名及作者。
SELECT BName, BAuth FROM BookWHERE BName LIKE’%计算机%’(6)在“图书”表中增加“出版时间”(BDate)项,其数据类型为日期型。
ALTER TABLE BookADD BDate datetime(7)在“图书”表中以“作者”建立一个索引。
CREATE INDEX Name ON Book(BAuth) desc2.(1)建立存书表和销售表。
第3章关系数据库标准语言SQL一、选择题1、SQL语言是的语言,易学习。
A.过程化 B.非过程化 C.格式化 D.导航式答案:B2、SQL语言是语言。
A.层次数据库 B.网络数据库 C.关系数据库 D.非数据库答案:C3、SQL语言具有的功能。
A.关系规范化、数据操纵、数据控制 B.数据定义、数据操纵、数据控制C.数据定义、关系规范化、数据控制 D.数据定义、关系规范化、数据操纵答案:B4、SQL语言具有两种使用方式,分别称为交互式SQL和。
A.提示式SQL B.多用户SQL C.嵌入式SQL D.解释式SQL 答案:C5、假定学生关系是S(S#,SNAME,SEX,AGE),课程关系是C(C#,CNAME,TEACHER),学生选课关系是SC(S#,C#,GRADE)。
要查找选修“COMPUTER”课程的“女”学生姓名,将涉及到关系。
A.S B.SC,C C.S,SC D.S,C,SC 答案:D6、若用如下的SQL语句创建一个student表:CREATE TABLE student(NO C(4) NOT NULL,NAME C(8) NOT NULL,SEX C(2),AGE N(2))可以插入到student表中的是。
A.(‘1031’,‘曾华’,男,23) B.(‘1031’,‘曾华’,NULL,NULL)C.(NULL,‘曾华’,‘男’,‘23’) D.(‘1031’,NULL,‘男’,23) 答案:B7、当两个子查询的结果时,可以执行并,交,差操作.A.结构完全不一致 B.结构完全一致C.结构部分一致D.主键一致答案:B第8到第10题基于这样的三个表即学生表S、课程表C和学生选课表SC,它们的结构如下:S(S#,SN,SEX,AGE,DEPT)C(C#,CN)SC(S#,C#,GRADE)其中:S#为学号,SN为姓名,SEX为性别,AGE为年龄,DEPT为系别,C#为课程号,CN为课程名,GRADE为成绩。
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 C实用文档where 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 C实用文档where 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 s实用文档where not exists((select c#from cwhere t#=(select t#from twhere tname='LIU')) except(select c# from sc wheresc.s#=s.s#) );3.4 设有两个基本表R(A,B,C)和S(A,B,C),试用SQL查询语句表达下列关系代数表达式:① R∪S ② R∩S ③ R-S ④R×S ⑤πA,BπB,C(S)⑥π1,6(σ3=4(R×S)⑦π1,2,3(R S)⑧R÷πC(S)解:①(SELECT * FROM R)UNION(SELECT * FROM S);②(SELECT * FROM R)3=3实用文档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 RY实用文档WHERE RY.A=RX.A AND RY.B=RX.B ANDRY.C=S.C));3.6 试叙述SQL语言的关系代数特点和元组演算特点。
第三章SQL一、填空题1、在SQL查询时,如果要去掉查询结果中的重复组,需要用()2、在SQL中使用()命令建立基本表3、在SQL中使用()命令修改数据库模式。
4、在SQL的SELECT语句中,不仅可以出现属性名,还可以出现()。
5、当基本表中增加一个新列后,各元组在新列上的值是()。
6、在SQL中表示并集的关键字是(0)。
7、在SQL中表示差集的关键字是()。
8、SQL对嵌套查询的处理方法是从()层向()层处理。
9、在SQL中定义视图时,需要用关键字()连接子查询来完成。
10、SQL包括了数据定义、数据操纵和()等功能。
11、SQL对嵌套查询的处理方法是从()层向()层处理。
二、单选题1、在SQL中,用户可以直接操纵的是()。
A. 基本表B. 视图C. 基本表或视图D. 基本表和视图2、在SQL中,与关系代数中的投影运算对应的字句是()。
A. SELECTB. FROMC. WHERED.ORDER BY3、SELECT语句执行的结果是()。
A. 数据项B. 元组C. 表D. 数据库4、关系数据库的标准语言是()。
A. DDLB. SQLC. ORACLED. DBMS5、在SELECT语句中使用*表示()。
A. 选择任何属性B. 选择全部属性C. 选择全部元组D. 选择键码6、使用CREATE TABLE语句建立的是()。
A. 数据库B. 表C. 视图D. 索引7、在SELECT语句中使用MIN(属性名)时,属性名()。
A. 必须是数值型B. 必须是字符型C. 必须是数值型或字符型D.不限制数据类型8、使用CREATE VIEW语句建立的是()。
A. 数据库B. 表C. 视图D. 索引9、在SQL中使用UPDA TE对表中数据进行修改时,应使用的子句是()。
A. WHEREB. FROMC. V ALUESD. SET10、使用CRETE INDEX语句建立的是()。
11、在SQL的语句中,ALTER的作用是()。
A. 删除基本表B. 修改基本表中的数据C. 修改基本表中的结构D. 修改视图12、在SELECT语句中使用A VG(属性名)时,属性名()。
A. 必须是数值型B. 必须是字符型C. 必须是数值型或字符型D.不限制数据类型13、在SQL中用关键字EXCEPT表示的运算是集合的()。
A. 交集B. 并集C. 差集D. 连接14、在SQL的排序子句:“ORDER BY总分DESC ,英语DESC”,表示()。
A. 总分和英语分数都是最高的在前面B. 总分和英语分数之和最高的在前面C. 总分高在前,总分相同时英语分数高的在前面D. 总分和英语分数之和最高的在前面,相同时英语分数高的在前面15、当选择满足一定条件的元组进行分组时,应使用的关键字是()。
A. WHEREB. GROUPC. ORDER BYD. HA VING16、SQL语言具有的功能是()A. 关系规范化,数据操作,数据控制B. 数据操作,数据定义,数据控制C. 关系规范化,查询优化,数据控制D. 关系规范化,数据定义,数据控制17、SQL语言是()的语言,容易学习。
A. 过程化B.非过程化C.格式化D.导航式18、在视图上不能完成的操作是()。
A.更新视图B.查询C.在视图上定义新的表D.在视图上定义新的视图19、SQL语言集数据查询、数据操纵、数据定义和数据控制功能于一体,其中,CREATE、DROP、ALTER语句是实现哪种功能()。
A.数据查询B.数据操纵C.数据定义D.数据控制20、SQL语言中,删除一个视图的命令是()。
A.DELETEB.DROPC.CLEARD.REMOVE21、在SQL语言中的视图VIEW是数据库的()。
A.外模式B.模式C.内模式D.存储模式22、下列的SQL语句中,()不是数据定义语句。
A.CREATE TABLEB.DROP VIEWC.CREATE VIEWD.GRANT23、若要撤销数据库中已经存在的表S,可用()。
A.DELETE TABLE SB.DELETE SC.DROP TABLE SD.DROP S24、若要在基本表S中增加一列CN(课程名),可用()。
A. ADD TABLE S(CN CHAR(8))B. ADD TABLE S(CN CHAR(8))C. ALTER TABLE S ADD(CN CHAR(8))D. ALTER TABLE S (ADD CN CHAR(8))25、学生关系模式S(S#,Sname,Sex,Age),S的属性分别表示学生的学号、姓名、性别、年龄。
要在表S中删除一个属性“年龄”,可选用的SQL语句是()。
A.DELETE Age from SB.ALTER TABLE S DROP AgeC.UPDATE S AgeD.ALTER TABLE S …Age‟26、有关系S(S#,SNAME,SAGE),C(C#,CNAME),SC(S#,C#,GRADE)。
其中S#是学生号,SNAME是学生姓名,SAGE是学生年龄,C#是课程号,CNAME 是课程名称。
要查询选修“ACCESS”课的年龄不小于20的全体学生姓名的SQL语句是SELECT SNAME FROM S,C,SC WHERE子句。
这里的WHERE子句的内容是()。
A.S.S# = SC.S# and C.C# = SC.C# and SAGE>=20 and CNAME=…ACCESS‟B.S.S# = SC.S# and C.C# = SC.C# and SAGE in>=20 and C NAME in …ACCESS‟C.SAGE in>=20 and CNAME in …ACCESS‟D.SAGE>=20 and CNAME=‟ ACCESS‟27、设关系数据库中一个表S的结构为S(SN,CN,grade),其中SN为学生名,CN为课程名,二者均为字符型;grade为成绩,数值型,取值范围0-100。
若要把“张二的化学成绩80分”插入S中,则可用()。
A. ADD INTO S V ALUES(‟张二‟,‟化学‟,‟80‟)B. INSERT INTO S V ALUES(‟张二‟,‟化学‟,‟80‟)C. ADD INTO S V ALUES(‟张二‟,‟化学‟,80)D. INSERT INTO S V ALUES(‟张二‟,‟化学‟,80)28、设关系数据库中一个表S的结构为:S(SN,CN,grade),其中SN为学生名,CN为课程名,二者均为字符型;grade为成绩,数值型,取值范围0-100。
若要更正王二的化学成绩为85分,则可用()。
A、UPDATE S SET grade=85 WHERE SN=‟王二‟ AND CN=‟化学‟B、UPDATE S SET grade=‟85‟ WHERE SN=‟王二‟ AND CN=‟化学‟C、UPDATE grade=85 WHERE SN=‟王二‟ AND CN=‟化学‟D、UPDATE grade=‟85‟ WHERE SN=‟王二‟ AND CN=‟化学‟29、在SQL语言中,子查询是()。
A.返回单表中数据子集的查询语言B.选取多表中字段子集的查询语句C.选取单表中字段子集的查询语句D.嵌入到另一个查询语句之中的查询语句30、有关系S(S#,SNAME,SEX),C(C#,CNAME),SC(S#,C#,GRADE)。
其中S#是学生号,SNAME是学生姓名,SEX是性别,C#是课程号,CNAME是课程名称。
要查询选修“数据库”课的全体男生姓名的SQL语句是SELECT SNAME FROM S,C,SC WHERE子句。
这里的WHERE子句的内容是()。
A. S.S# = SC.S# and C.C# = SC.C# and SEX=‟男‟ and CNAME=‟数据库‟B. S.S# = SC.S# and C.C# = SC.C# and SEX in‟男‟and CNAME in‟数据库‟C. SEX ‟男‟ and CNAME ‟ 数据库‟D. S.SEX=‟男‟ and CNAME=‟ 数据库‟31、若用如下的SQL语句创建了一个表SC:CREATE TABLE SC (S# CHAR(6)NOTNULL,C# CHAR(3)NOT NULL,SCORE INTEGER,NOTE CHAR(20));向SC 表插入如下行时,()行可以被插入。
A. (‟201009‟,‟111‟,60,必修)B. (‟200823‟,‟101‟,NULL,NULL)C. (NULL,‟103‟,80,‟选修‟)D. (‟201132‟,NULL,86,‟ ‟)32、假设学生关系S(S#,SNAME,SEX),课程关系C(C#,CNAME),学生选课关系SC(S#,C#,GRADE)。
要查询选修“Computer”课的男生姓名,将涉及到关系()。
A.SB.S,SCC.C,SCD.S,C,SC四、判断题1、可以用关键字“AS”给某个属性命别名。
2、“=NULL“表示一个值是空值。
3、”%”表示任意一个字符,”_”表示任意数量的字符4、在SQL中,ORDER BY表示对输出结果进行排序。
5、EXISTS的含义与存在量词相同。
6、视图内容要保存在一个新的数据库中。
7、在视图中插入一个元祖,该元祖会同时插入到基本表中。
8、ALTER TABLE MovieMODIFY Title CHAR(15)表示将Title属性的数据类型改成字符串型,长度为15.9、如果对关系的查询比更新频繁得多,对使用频率高的属性建立索引比较有价值。
五、简答题1、什么是嵌套查询?什么是相关子查询?2、简述SQL语言的主要特点?3、关系模式如下:商品P(ONO,PN,COLOR,PRICE)商店S(SNO,SN,CITY)销售SP(PNO,SNO,QTY)用SQL写出查询语句:查询销售商品‟TV‟的商店名SN查询与商品‟TV‟颜色相同的商品名PN查询至少销售商品P1,P2(商品号)两种商品的商店名SN不销售商品P2(商品号)的商店名SN只销售商品P2(商品号)的商店名所有商店都销售的商品的商品号将在London销售红色商品的商店号SNO,商店名SN建立视图RLS查询销售所有商品的商店名SN4、对于关系模式S(Sno,Sname,Age,Dept); C(Cno,Cname, Teacher); SC(Sno,Cno, Score),用SQL写出下列查询语句:选修课程‟DB‟的学生姓名查询课程名和直接先行课的课程名以及间接先行课的课程名所有学生都选修的课程名CN将选修课程‟DB‟的学生号,姓名建立视图SDB查询所有以‟MA T‟为先行课的课程的学生姓名Sname找出刘老师所授课程的课程号和课程名找出年龄小于22岁的女学生的学号和姓名找出至少选修刘老师讲的一门课的学生姓名找出“程序设计”课成绩在90分以上的学生的姓名找出不选C3课的学生姓名找出至少选修C1课和C2课的学生学号求孙老师讲的每门课的学生平均成绩统计选修各门课的学生人数。