数据库习题答案-3

合集下载

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

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

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章习题参考答案

数据库第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,其功能是________。

数据库概论第1-3章习题参考答案

数据库概论第1-3章习题参考答案

第1章绪论习题参考答案1、试述数据、数据库、数据库管理系统、数据库系统的概念。

(参见P3、4、5页)参考答案:描述事物的符号记录称为数据;数据库是长期储存在计算机内的、有组织的、可共享的数据集合;数据库管理系统是位于用户与操作系统之间的一层数据管理软件; 数据库系统是指在计算机系统中引入数据库后的系统,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员和用户构成。

2.使用数据库系统有什么好处?(参见P12页)参考答案:数据库系统使信息系统从以加工数据的程序为中心转向围绕共享的数据库为中心的阶段,这样既便于数据的集中管理,又有利于应用程序的研制和维护,提高了数据的利用率和相容性,提高了决策的可靠性。

3.试述文件系统与数据库系统的区别和联系。

(8、9、10页)参考答案:1)数据结构化是数据库与文件系统的根本区别。

在文件系统中,相互独立的文件的记录内部是有结构的,管其记录内部已有了某些结构,但记录之间没有联系。

数据库系统实现整体数据的结构化,是数据库的主要特征之一。

2)在文件系统中,数据的最小存取单位是记录,粒度不能细到数据项。

而在数据库系统中,存取数据的方式也很灵活,可以存取数据库中的某一个数据项、一组数据项一个记录或或一组记录。

3)文件系统中的文件是为某一特定应用服务的,文件的逻辑结构对该应用程序来说是优化的,因此要想对现有的数据再增加一些新的应用会很困难,系统不容易扩充。

而在数据库系统中数据不再针对某一应用,而是面向全组织,具有整体的结构化。

5.试述数据库系统的特点。

(9、10、11页)参考答案:数据结构化;数据的共享性高、冗余度低、易扩充;数据独立性高;数据由DBMS统一管理和控制。

6.数据库管理系统的主要功能有哪些? (4页)参考答案:数据定义功能、数据操纵功能、数据库的运行管理、数据库的建立和维护功能。

7.试述数据模型的概念(13页)、数据模型的作用、数据模型的三个要素。

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

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

三、设计题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

数据库原理及应用-考试题3

《数据库原理及应用》试题3一、选择题(每题1分,共20分)1、数据库系统的特点是_________、数据独立、减少数据冗余、避免数据不一致和加强了数据保护。

A、数据共享B、数据存储C、数据应用D、数据保密(难度系数C)正确答案:A2、在数据库中存储的是_________。

A、数据B、数据模型C、信息D、数据以及数据之间的联系(难度系数C)正确答案:D3、数据库系统的数据独立性是指_________。

A、不会因为数据的变化而影响应用程序B、不会因为系统数据存储结构与数据逻辑结构的变化而影响应用程序C、不会因为存储策略的变化而影响存储结构D、不会因为某些存储结构的变化而影响其他的存储结构(难度系数C)正确答案:B4、DB、DBMS和DBS三者之间的关系是_________。

A、DBS与DB和DBMS无关B、DBMS包括DBS和DBC、DBS包括DB和DBMSD、DB包括DBMS和DBS(难度系数B)正确答案:C5、数据库管理系统能实现对数据库中数据的查询、插入、修改和删除等操作.这种功能称为_________。

A、数据操纵功能B、数据管理功能C、数据定义功能D、数据控制功能(难度系数A)正确答案:A6、关系数据库中,实现表与表之间的联系是通过_________。

A、实体完整性规则B、值域C、用户自定义完整性D、参照完整性规则(难度系数B)正确答案:D7、设关系R有K1个元组,关系S有K2个元组,则关系R和S进行笛卡尔积操作后的结果关系中的元组数目是_________。

A、K1+K2B、≥K1+K2C、K1×K2D、≤K1×K2(难度系数A)正确答案:C8、对关系的完整性约束通常包括_________三种。

A、实体完整性、属性完整性、关系完整性;B、实体完整性、参照完整性、用户定义完整;C、实体完整性、属性完整性、用户定义完整;D、实体完整性、属性完整性、参照完整性;(难度系数A)正确答案:B9、在SQL中,建立视图用的命令是_________。

《数据库原理》试卷及答案3

《数据库原理》试卷及答案3

广州大学2007--2008学年第一学期考试卷(A)科目:《数据库原理》一、选择题(共20分,每选1 分)1、在关系模式中,视图是三级模式结构中的(D)A. 内模式B. 模式C. 存储模式D. 外模式2、在数据库的三级模式中,内模式有(A)A. 1个B. 2个C. 3个D. 多个3、在关系数据库中,当关系的型改变时,用户程序也可以不变。

这是(B)A. 物理独立性B. 逻辑独立性C. 位置独立性D. 存储独立性4、公司中有多个部门和多名职员,每个职员只能属于一个部门,一个部门可以有多名职员,从部门到职员的联系类型是(D)A. 多对多B. 一对一C. 多对一D. 一对多5、为数据表创建索引的目的是( A )A. 提高查询的检索性能B. 创建唯一索引C. 创建主键D. 归类6、设有一张数据表“DEPT”,包含两个字段DNO和DNAME,如果要找出倒数第三个字母为W,并且至少包含4个字母的DNAME,则查询条件子句应写成WHERE DNAME LIKE( B)A. ‘_ _ W _ %’B. ‘_ % W _ _’C. ‘_ W _ _’D. ‘_ W _ %’7、SQL语言中,删除一个表的命令是(B)A. DELETE TABLEB. DROP TABLEC. CLEAR TABLED. REMORE TABLE8、设有关系模式R(C,T,H,R,S),其中各属性的含义是:C表示课程,T表示教员,H表示上课时间,R表示教室,S表示学生。

根据语义有如下函数依赖集:F={ C→T, (H,R)→C, (H,T)→R, (H,S)→R },则关系模式R的码是(D)A. CB.(H,R)C.(H,T)D.(H,S)9、接9题,关系模式R的规范化程度最高达到(B)A. 1NFB. 2NFC. 3NFD. BCNF10、下列聚合函数中哪一个是计算列的平均值(C)A. SUM ( )B. MAX ( )C. A VG ( )D. COUNT ( )11、Where date1 >= ‘2002-02-01’ and date1 <= ‘2002-06-30’ 相当于( C)A. Where date1 >=’2002-02-01’ or date1 <= ‘2002-06-30’B. Where date1 <=’2002-02-01’ and date1 >= ‘2002-06-30’C. Where date1 between ’2002-02-01’ and ‘2002-06-30’D. Where date1 between ‘2002-02-01’ or ‘2002-06-30’12、一个1:n联系可以转换为一个独立的关系模式,关系的码为(C)A. 实体的码B. 各实体码的组合C. n端实体的码D. 每个实体的码13、下列关于函数依赖的叙述中,哪一条是不确定的( B )A. 由X→Y, X→Z, 有X→Y ZB. 由XY→Z, 有X→Z, Y→ZC. 由X→Y, WY→Z, 有XW→ZD. 由X→Y, 及Z Y, 有X→Z14、关系数据模型(D)A.只能表示实体间的1:1联系B.只能表示实体间的1:n联系C.只能表示实体间的m:n联系D.可以表示实体间的上述三种联系15、数据库(DB)、数据库系统(DBS)和数据库管理系统(DBMS)三者之间的关系是(A)A. DBS包括DB和DBMSB. DBMS包括DB和DBSC. DB包括DBS和DBMSD. DBS就是DB,也就是DBMS16、设有T1和T2两个事务,其并发操作如下表所示,下面评价中正确的是(C)表-1并发操作A. 该操作不存在问题B. 该操作丢失修改C. 该操作不能重复读D. 该操作读“脏数据”17、授予用户Jean删除帐户表的权限,使用的SQL语句是(A)A. GRANT DELETE ON 帐户TO JeanB. GRANT DELETE TO Jean ON 帐户C. GRANT DELETE TO 帐户ON JeanD. GRANT DELETE ON Jean TO 帐户18、在关系代数的专门关系运算中,从表中取出满足条件的属性的操作称为(B)A. 选择B. 投影C. 连接D. 扫描19、下列说法正确的是( B)A. 视图是观察数据的一种方法,只能基于基本表建立。

数据库第三章习题及答案

数据库第三章习题及答案

第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为成绩。

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

《数据库习题答案》来自五星文库
点这里,有很多篇《数据库习题答案》
在线阅读本文:
数据库习题答案
导读:第三章习题,1.关系数据库设计理论,数据依赖范式和关系模式的规范化设计方法,其中数据依赖起着核心的作用,2.关系数据库中的关系模式至少要满足第一范式,如果每个属性值都是不可再分的最小数据单位,(2)试分析模式R的数据冗余问题,关系R中的C属性会存在在数据冗余,相应地原来存储在一张二维表内的数据就要分散存储到多张二维表中,第四章习题,A删除基本表B修改基本表中的数据,A数据项B 元组,C表D数据库
第三章习题
一、单项选择题
1.在关系模型R中,函数依赖X→Y的语义是(B )A.在R的某一关系中,若两个元组的X值相等,则Y值也相等
B.在R的每一关系中,若两个元组的X值相等,则Y值也相等
C.在R的某一关系中,X值应与Y值相等
D.在R的每一关系中,X值应与Y值相等
2.设学生关系模式为:学生(学号,姓名,年龄,性别,成绩,专业),则该关系模式的主键是( B )
A.性别B.学号
C.学号,姓名D.学号,姓名,性别
3.如果X→Y(Y不包含于X,且Y不能决定X)和Y→Z成立,那么X→Z成立。

这条规则称为( B )
A.自反律B.传递律
C.伪传递律D.增广律
4.关系模式R2NF,则R一定是(b )
A.1NF B.3NF
C.BCNF D.4NF
5.设一关系模式为:运货路径(顾客姓名,顾客地址,商品名,供应商姓名,供应商地址),则该关系模式的主键是( C )A.顾客姓名,供应商姓名,供应商地址B.顾客姓名,商品名
C.顾客姓名,供应商姓名,商品名D.顾客姓名,顾客地址
6.下列有关范式的叙述中正确的是(B )
A.如果关系模式R1NF,且R中主属性完全函数依赖于主键,则R是2NF
B.如果关系模式R3NF,则R2NF一定成立
C.如果关系模式R1NF,则只要消除了R中非主属性对主键的传递依赖,则R可转换成2NF
D.如果关系模式R1NF,则只要消除了R中非主属性对主键的部分依赖,则R可转换成3NF
7.关系模式学生(学号,课程号,名次),若每一名学生每门课程有一定的名次,每门课程每一名次只有一名学生,则以下叙述中错误的是( B )
A.(学号,课程号)和(课程号,名次)都可以作为候选键B.只有(学号,课程号)能作为候选键
C.该关系模式属于第三范式
D.该关系模式属于BCNF
8.已知关系模式R(ABCD),F={A→C,B→C,C→D },则以下成立的是( B )
A.A→B B.A→D
C.AD→BC D.AC→BD
9.如果X→Y且ZU成立,那么XZ→YZ成立,这条规则称为(D )A.自反律B.传递律`
C.伪传递律D.增广律
10.能够消除多值依赖引起的冗余是( D )
A.1NF B.2NF
C.3NF D.4NF
二、填空题
1.关系数据库设计理论,数据依赖范式和关系模式的规范化设计方法。

其中数据依赖起着核心的作用。

2.关系数据库中的关系模式至少要满足第一范式。

3.非规范化的关系模式在实际应用中可能存在的问题有更新异常。

4.消除了非主属性对主码的部分依赖的关系模式,称为第二范式模式。

5.消除了非主属性对主码传递和部分依赖的关系模式,称为第三范式
6.消除了每一属性对主码传递和部分依赖的关系模式,称为BCNF模式。

7.关系模式R(A,B,C)中的主码是(A,B)构成的属性组,且B→C成立,但C→B不成立,则称C与主码之间存在的函数依赖为部分函数依赖。

8.关系模式R(A,B,C)中的主码是A,且B→C成立,但B→A 不成立,则称B与主码A之间存在的函数依赖为传递函数依赖。

9.在进行模式分解的同时必须考虑的两个问题是无损连接性和保持函数依赖
10.Armstrong公理的三条推理规则是自反律增广律传递律。

三、简答题
l.理解并给出下列术语的定义:
函数依赖、部分函数依赖、完全函数依赖、传递依赖、1NF、2NF、3NF、BCNF。

函数依赖:设R(U)是属性集U上的关系模式。

X,Y是U的子集。

若对于R(U)的任意一个可能的关系r,r中不可能存在两个元组
在X上的属性值相等,而在Y上的属性值不等,则称X函数确定Y 或Y函数依赖于X。

部分函数依赖:设关系模式R(U)中,X,YU,若X→Y,但对于X的某一个真子集Z→Y成立,则称Y部分函数依赖于X。

完全函数依赖:设关系模式R(U)中,X,YU,如果X→Y,并且对于X的任何一个真子集Z,Z→Y都不成立,则称Y完全依赖于X,记作X--->Y。

传递依赖:在关系模式R(U)中,设X、Y、Z是R的三个不同属性子集,如果X→Y(YX)成立,但Y→X不成立,而Y→Z(ZY),则称Z对X传递函数依赖。

1NF:在关系模式R中的每一个具体关系r中,如果每个属性值都是不可再分的最小数据单位,则称R是第一范式关系模式,简记为R1NF。

2NF:若关系模式R是1NF,且所有非主属性都完全函数依赖于任意一个候选码,则称R 是第二范式关系模式,简记为R2NF。

3NF:若关系模式R是2NF,且所有非主属性对任何候选关键字都不存在传递函数依赖,则称R是第三范式关系模式,简记为R3NF。

BCNF:若关系模式R是1NF,如果对于R的每个函数依赖X→Y,若YX,则X必含有候选码,则称R是BCNF范式。

换句话说,在关系模式R中,如果每一个决定因素都包含候选码,则RBCNF。

2.设一关系为:订单(订单号,顾客姓名,商品货号,定购数量,交货日期),判断此关系属于哪一范式,为什么
此关系的主码是订单号,主属性只有一个,因此它属于BCNF。

3.设关系模式R(A,B,C),F是R上成立的FD集,有F={ A→C,B→C }。

此题需将题目改为:
设关系模式R(A,B,C),F是R上成立的FD集,有F={ A→B,B→C }。

(1)试说明为什么R不是3NF模式
由于R的主码为A,存在传递函数依赖:A→B,B→C;因此R 不属于第三范式。

(2)试分析模式R的数据冗余问题。

关系R中的C属性会存在在数据冗余。

(3)试把R分解成3NF模式集。

分解成3NF模式集:R1(A,B);R2(B,C)。

4.写出关系模式规范化的步骤。

1NF(消除非主属性对码的部分函数依赖)→2NF(消除非主属性对码的传递函数依赖)→ 3NF(消除主属性对码的部分和传递函数依赖)→BCNF
5.试述模式分解时考虑无损连接性和保持函数依赖的意义。

一个关系分解为多个关系,相应地原来存储在一张二维表内的数据就要分散存储到多张二维表中,要使这个分解有意义,起码的要求是后者不能丢失前者的信息,如果一个分解具有无损连接性,则它能够保证不丢失信息。

而如果一个分解保持了函数依赖,则它可以减轻或解决各种异常情况。

第四章习题
一、单项选择题
1.在SQL中,与关系代数中的投影运算对应的子句是(A )A SELECT B FROM
C WHERE
D ORDER BY
2. 在SQL的语句中,ALTER的作用是(C)
A 删除基本表
B 修改基本表中的数据
C 修改基本表的结构
D 修改视图
3. 用SQL语言描述“在教师表中查找女教师的全部信息”,以下描述正确的是( C )
A SELECT FROM 教师表IF(性别=女)
B SELECT 性别FROM 教师表IF(性别=女)
C SELECT * FROM 教师表WHERE(性别=女)
D SELECT * FROM 性别WHERE(性别=女)
4. 在基本SQL语言中,不可以实现(D)
A 定义视图
B 定义基本表
C 查询视图和基本表
D 并发控制
5. SELECT语句执行的结果是(B)
A 数据项
B 元组
C 表
D 数据库
6.在SQL中,用户可以直接操作的是(A)
A 基本表
B 视图
C 基本表或视图
D 基本表和视图
7.在SQL中使用UPDATE对表中数据进行修改时,应使用的子句是(D)
A WHERE
B FROM
C VALUES
D SET
8.SQL语言具有的功能是(B)
A 关系规范化,数据操作,数据控制
B 数据定义,数据操作,数据控制
C 数据定义,关系规范化,数据控制
D 数据定义,关系规范化,数据操作
9.当选择满足一定条件的元组进行分组时,应使用的关键字是(C )
A SELECT
B GROUP
C WHERE
D HAVING
10.使用CREATE INDEX语句建立的是(C )
A 数据库
B 表
C 索引
D 视图
二、填空题
1.SQL插入记录的命令是INSERT ,删除记录的命令是____,更新记录的命令是__。

2.SQL查询语句中,在SELECT子句中允许出现列名和___。

3. SQL语句中,Order By可以对___进行排序。

4. 在SQL查询语句中,如果要去掉查询结果中的重复值,需使用__ _。

五星文库包含总结汇报、办公文档、文档下载、资格考试、党团工作、外语学习、教学研究、行业论文、工作范文以及数据库习题答案等内容。

本文共6页123456
五星文库
免费文档下载。

相关文档
最新文档