数据库第3章习题解答
- 格式:ppt
- 大小:305.00 KB
- 文档页数:11
3.5设有一个SPJ数据库,包括S,P,J,SPJ四个关系模式:S(SNO,SNAME,STATUS,CITY); P(PNO,PNAME,COLOR,WEIGHT); J(JNO,JNAME,CITY);SPJ(SNO,PNO,JNO,QTY);1、供应商表S由供应商代码(SNO)、供应商姓名(SNAME)、供应商状态(STATUS)、供应商所在城市(CITY)组成;2、零件表P由零件代码(PNO)、零件名(PNAME)、颜色(COLOR)、重量(WEIGHT)组成;3、工程项目表J由工程项目代码(JNO)、工程项目名(JNAME)、工程项目所在城市(CITY)组成;4、供应情况表SPJ由供应商代码(SNO)、零件代码(PNO)、工程项目代码(JNO)、供应数量(QTY)组成,表示某供应商供应某种零件给某工程项目的数量为QTY。
试用关系代数语言完成如下查询:1)找出所有供应商的姓名和所在城市;2)找出所有零件的名称、颜色、重量;3)找出使用供应商S1所供应零件的工程号码;4)找出工程项目J2使用的各种零件的名称及其数量;5)找出上海厂商供应的所有零件号码;6)找出使用上海产的零件的工程号码;7)找出没有使用天津产的零件的工程号码;8)把全部红色零件的颜色改成蓝色;9)由S5供给J4的零件P6改为由S3供应,请作必要的修改;10)从供应商关系中删除S2的记录,并从供应情况关系中删除相应的记录;11)求供应工程J1零件的供应商号码SNO;12)求供应工程J1零件P1的供应商号码SNO;13)求供应工程J1零件为红色的供应商号SNO;14)求没有使用天津供应商生产的红色零件的工程号JNO;15)求S1提供的零件名PNAME;16)求给工程J1和J2提供零件的供应商号码SNO;解:1)找出所有供应商的姓名和所在城市;Select SNAME,CITY From S2)找出所有零件的名称、颜色、重量;Select PNAME,COLOR,WEIGHT From P3)找出使用供应商S1所供应零件的工程号码;Select JNO From SPJ Where SNO= ‘S1’4)找出工程项目J2使用的各种零件的名称及其数量;Select PNAME,QTY From SPJ,PWhere SPJ.PNO=P.PNO And JNO=‘J2’5)找出上海厂商供应的所有零件号码;Select PNO From S,SPJWhere SPJ.SNO=S.SNO And CITY=‘上海’6)找出使用上海产的零件的工程号码;Select JNAME From J,SPJ,S Where J.JNO=SPJ.JNOAnd S.SNO=SPJ.SNO And S.CITY=‘上海’7)找出没有使用天津产的零件的工程号码;Select JNO From SPJ Where SNONOT IN(Select SNO From S Where CITY= ‘天津’)8)把全部红色零件的颜色改成蓝色;Updat P SET COLOR=‘蓝’ Where COLOR=‘红’9)由S5供给J4的零件P6改为由S3供应,请作必要的修改;Updat SPJ SET SNO=‘S3’Where SNO=‘S5’ And JNO=‘J4’ And PNO=‘P6’10)从供应商关系中删除S2的记录,并从供应情况关系中删除相应的记录;Delete From S Where SNO=‘S2’Delete From SPJ Where SNO=‘S2’11)求供应工程J1零件的供应商号码SNO;Select SNO From SPJ Where JNO=‘J1’12)求供应工程J1零件P1的供应商号码SNO;Select SNO From SPJ Where JNO=‘J1’ And PNO=‘P1’13)求供应工程J1零件为红色的供应商号SNO;Select SNO From P,SPJWhere P.PNO=SPJ.PNO And JNO=‘J1’ And COLOR=‘红’14)求没有使用天津供应商生产的红色零件的工程号JNO; Select JNO From SPJ Where JNO NOT IN(Select JNO From S,SPJ,P Where S.SNO=SPJ.SNOAnd P.PNO=SPJ.PNO And COLOR=‘红’ And CITY=‘天津’)15)求S1提供的零件名PNAME;Select PNAME From SPJ,PWhere P.PNO=SPJ.PNO And SNO=‘S1’16)求同时给工程J1和J2提供零件的供应商号码SNO;Select SNO From SPJ Where JNO=‘J1’And SNO IN(Select SNO From SPJ Where JNO=‘J2’)或Select SNO From SPJ Where JNO=‘J1’INTERSECT Select SNO From SPJ Where JNO=‘J1’3.6 什么是基本表?什么是视图?两者的区别和联系是什么?3.11 请为三建工程建立一个供应情况的视图,包括供应商代码SNO、零件代码PNO、供应数量QTY。
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)(完)。
《数据库习题答案》来自五星文库点这里,有很多篇《数据库习题答案》在线阅读本文:数据库习题答案导读:第三章习题,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.关系模式R?2NF,则R一定是(b )A.1NF B.3NF5.设一关系模式为:运货路径(顾客姓名,顾客地址,商品名,供应商姓名,供应商地址),则该关系模式的主键是( C )A.顾客姓名,供应商姓名,供应商地址 B.顾客姓名,商品名C.顾客姓名,供应商姓名,商品名 D.顾客姓名,顾客地址6.下列有关范式的叙述中正确的是( B )A.如果关系模式R?1NF,且R中主属性完全函数依赖于主键,则R是2NFB.如果关系模式 R?3NF,则R?2NF一定成立C.如果关系模式R?1NF,则只要消除了R中非主属性对主键的传递依赖,则R可转换成2NFD.如果关系模式R?1NF,则只要消除了R中非主属性对主键的部分依赖,则R可转换成3NF7.关系模式学生(学号,课程号,名次),若每一名学生每门课程有一定的名次,每门课程每一名次只有一名学生,则以下叙述中错误的是( B )A.(学号,课程号)和(课程号,名次)都可以作为候选键B.只有(学号,课程号)能作为候选键C.该关系模式属于第三范式D.该关系模式属于BCNF8.已知关系模式R(ABCD),F={A→C,B→C,C→D },则以下成立的是( B )A.A→B B.A→DC.AD→BC D.AC→BD9.如果X→Y且Z?U成立,那么XZ→YZ成立,这条规则称为( D )A.自反律 B.传递律`C.伪传递律 D.增广律10.能够消除多值依赖引起的冗余是( D )A.1NF B.2NF二、填空题1.关系数据库设计理论,数据依赖范式和关系模式的规范化设计方法。
《数据库习题答案》来自五星文库点这里,有很多篇《数据库习题答案》在线阅读本文:数据库习题答案导读:第三章习题,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.3NFC.BCNF D.4NF5.设一关系模式为:运货路径(顾客姓名,顾客地址,商品名,供应商姓名,供应商地址),则该关系模式的主键是( C )A.顾客姓名,供应商姓名,供应商地址B.顾客姓名,商品名C.顾客姓名,供应商姓名,商品名D.顾客姓名,顾客地址6.下列有关范式的叙述中正确的是(B )A.如果关系模式R1NF,且R中主属性完全函数依赖于主键,则R是2NFB.如果关系模式R3NF,则R2NF一定成立C.如果关系模式R1NF,则只要消除了R中非主属性对主键的传递依赖,则R可转换成2NFD.如果关系模式R1NF,则只要消除了R中非主属性对主键的部分依赖,则R可转换成3NF7.关系模式学生(学号,课程号,名次),若每一名学生每门课程有一定的名次,每门课程每一名次只有一名学生,则以下叙述中错误的是( B )A.(学号,课程号)和(课程号,名次)都可以作为候选键B.只有(学号,课程号)能作为候选键C.该关系模式属于第三范式D.该关系模式属于BCNF8.已知关系模式R(ABCD),F={A→C,B→C,C→D },则以下成立的是( B )A.A→B B.A→DC.AD→BC D.AC→BD9.如果X→Y且ZU成立,那么XZ→YZ成立,这条规则称为(D )A.自反律B.传递律`C.伪传递律D.增广律10.能够消除多值依赖引起的冗余是( D )A.1NF B.2NFC.3NF D.4NF二、填空题1.关系数据库设计理论,数据依赖范式和关系模式的规范化设计方法。
第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章绪论习题参考答案1、试述数据、数据库、数据库管理系统、数据库系统的概念。
(参见P3、4、5页)参考答案:描述事物的符号记录称为数据;数据库是长期储存在计算机内的、有组织的、可共享的数据集合;数据库管理系统是位于用户与操作系统之间的一层数据管理软件; 数据库系统是指在计算机系统中引入数据库后的系统,一般由数据库、数据库管理系统(及其开发工具)、应用系统、数据库管理员和用户构成。
2.使用数据库系统有什么好处?(参见P12页)参考答案:数据库系统使信息系统从以加工数据的程序为中心转向围绕共享的数据库为中心的阶段,这样既便于数据的集中管理,又有利于应用程序的研制和维护,提高了数据的利用率和相容性,提高了决策的可靠性。
3.试述文件系统与数据库系统的区别和联系。
(8、9、10页)参考答案:1)数据结构化是数据库与文件系统的根本区别。
在文件系统中,相互独立的文件的记录内部是有结构的,管其记录内部已有了某些结构,但记录之间没有联系。
数据库系统实现整体数据的结构化,是数据库的主要特征之一。
2)在文件系统中,数据的最小存取单位是记录,粒度不能细到数据项。
而在数据库系统中,存取数据的方式也很灵活,可以存取数据库中的某一个数据项、一组数据项一个记录或或一组记录。
3)文件系统中的文件是为某一特定应用服务的,文件的逻辑结构对该应用程序来说是优化的,因此要想对现有的数据再增加一些新的应用会很困难,系统不容易扩充。
而在数据库系统中数据不再针对某一应用,而是面向全组织,具有整体的结构化。
5.试述数据库系统的特点。
(9、10、11页)参考答案:数据结构化;数据的共享性高、冗余度低、易扩充;数据独立性高;数据由DBMS统一管理和控制。
6.数据库管理系统的主要功能有哪些? (4页)参考答案:数据定义功能、数据操纵功能、数据库的运行管理、数据库的建立和维护功能。
7.试述数据模型的概念(13页)、数据模型的作用、数据模型的三个要素。
数据库第三章习题参考答案范文大全第一篇:数据库第三章习题参考答案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. C2. B3. D4. C5. D6. A7. A8. B9. D 10. B11. C 12. D 13. A 14. D 15. B16. C 17. D 18. A 19. D 20. A二、填空题1. 数据库系统阶段2. 关系3. 物理独立性4. 操作系统5. 数据库管理系统(DBMS)6. 一对多7. 独立性8. 完整性控制9. 逻辑独立性10. 关系模型11. 概念结构(逻辑)12. 树有向图二维表嵌套和递归13. 宿主语言(或主语言)14. 数据字典15. 单用户结构主从式结构分布式结构客户/服务器结构浏览器/服务器结构第2章习题参考答案一、选择题1. A2. C3. C4. B5. B6. C7. B8. D9. C 10. A11. B 12. A 13. A 14. D 15. D二、填空题1. 选择(选取)2. 交3. 相容(或是同类关系)4. 并差笛卡尔积选择投影5. 并差交笛卡尔积6. 选择投影连接7. σf(R)8. 关系代数关系演算9. 属性10. 同质11. 参照完整性12. 系编号,系名称,电话办公地点13. 元组关系域关系14. 主键外部关系键15. R和S没有公共的属性第3章习题参考答案一、选择题1. B2. A3. C4. B5. C6. C7. B8. D9. A 10. D二、填空题结构化查询语言(Structured Query Language)数据查询、数据定义、数据操纵、数据控制外模式、模式、内模式数据库、事务日志NULL/NOT NULL、UNIQUE约束、PRIMARY KEY约束、FOREIGN KEY约束、CHECK 约束聚集索引、非聚集索引连接字段行数定义系统权限、对象权限基本表、视图12.(1)INSERT INTO S VALUES('990010','李国栋','男',19)(2)INSERT INTO S(No,Name) VALUES('990011', '王大友')(3)UPDATE S SET Name='陈平' WHERE No='990009'(4)DELETE FROM S WHERE No='990008'(5)DELETE FROM S WHERE Name LIKE '陈%'13.CHAR(8) NOT NULL14.o=o15.ALTER TABLE StudentADDSGrade CHAR(10)第4章习题参考答案一、选择题1. B2. B3. D4. B5. C6. D7. B8. D9. C 10. A二、填空题1. 超键(或超码)2. 正确完备3. 属性集X的闭包X + 函数依赖集F的闭包F +4. 平凡的函数依赖自反性5. {AD→C} φ6. 2NF 3NF BCNF7. 无损连接保持函数依赖8. AB BC BD9. B→φ B→B B→C B→BC10. B→C A→D D→C11. AB 1NF12. AD 3NF第5章习题参考答案一、选择题1. B2. B3. C4. A5. C6. D7. A8. C9. D 10. D11. B 12. B 13. A 14. D 15. A二、填空题安全性控制、完整性控制、并发性控制、数据库恢复数据对象、操作类型授权粒度、授权表中允许的登记项的范围原始数据(或明文)、不可直接识别的格式(或密文)、密文事务、原子性、一致性、隔离性、持久性丢失更新、污读、不可重读封锁、排它型封锁、共享封锁利用数据的冗余登记日志文件、数据转储事务故障、系统故障、介质故障完整性登录账号、用户账号public服务器、数据库第6章习题参考答案一、选择题1. B2. C3. C4. A5. C6. B7. C8. B9. D 10. C11. D 12. B 13. B 14. D二、填空题数据库的结构设计、数据库的行为设计新奥尔良法分析和设计阶段、实现和运行阶段需求分析概念结构设计自顶向下、自底向上属性冲突、命名冲突、结构冲突逻辑结构设计确定物理结构、评价物理结构数据库加载运行和维护物理数据字典需求分析载入第7章习题参考答案一、选择题1. B2.C3.B4.D5.A二、填空题局部变量、全局变量- -、/*……*/DECLARESQL、流程控制AFTER 触发器、INSTEAD OF 触发器插入表、删除表数据库备份、事务日志备份、差异备份、文件和文件组备份简单还原、完全还原、批日志还原硬盘、磁带、管道下面是古文鉴赏,不需要的朋友可以下载后编辑删除!!谢谢!!九歌·湘君屈原朗诵:路英君不行兮夷犹,蹇谁留兮中洲。