当前位置:文档之家› 大数据库期末重要题型总结材料

大数据库期末重要题型总结材料

题型:1 E-R图/文字描述/伪代码(实体-属性)/真实代码(create table)2关系代数表达式书写,画自然连接表格3 select语句书写(3部分)题型一 E-R图问题2[12标记〕:考虑下图描述的发票(发票)数据库的ER图。

(1)给出的从ER图的要求和约束的精确说明。

[5商标〕(2)转换图转换成关系模式,通过提供相应的CREATE TABLE语句。

指定所有键和外键约束。

Question 2 [12 marks]: Consider the following figure that describes the CME-R diagram of an invoice(发票) database.(1) Give a precise specification of the requirements and constraints fromthe E-R diagram. [5marks](2) Translate the diagram into relational model by supplying theappropriate CREATE TABLE statements. Specify all the key and foreign keyconstraints.[7 marks]矩形:实体。

多个实体的集合是实体集。

椭圆形:属性(带有下划线是主码)。

菱形:联系集。

有箭头的一方是“一”,没有箭头是“多”,从有箭头的开始分析:A(有箭头)对B,一个A对多个B,一个B只有一个A。

联系集有没有属性跟要不要描述联系集是没有关系的!但是一般没有属性就不写,有属性就写。

联系集有写时,实体集不需要写上对方的主码,有属性的联系集,多对多或多对一时,两边的实体集的主码都作为外码写进此联系集。

一对一时,任选一个实体集的主码;没写时,实体集多的一方要写上一的一方的主码,如果联系集有属性,还要把属性写到多的一方。

[7商标〕Question 2 [12 marks]: 化E-R 图为文字描述1分别写每个主体集的主体名和属性以及主码(带下划线的)2根据是否有箭头和箭头方向描述主体间的关系3联系集的属性描述An invoice has attributes: Invoice#(primary key), TotalOrderAmt, Date,Terms, ShipVia. A customer has attributes: Cust#(primary key), CName,Street, City, State, Zip, Phone. A product has attributes:Prod#(primary key), StandardPrice, Description. The relationshipbetween invoice and customer is many-to-one. One invoice can relateto only one customer, while one customer can relate to any number ofinvoices. The relationship between invoice and product is many-to-many.Any number of products can be placed in one invoice, and one productcan appear in different invoices. The relationship between invoice andproduct has two attributes: SellPrice and Quantity.发票有属性:发票#(主键),TotalOrderAmt ,日期,条款,SHIPVIA 。

一位顾客有属性:卡斯特#(主键),CNAME ,街道,城市,州,邮编,。

一个产品有属性:PROD #(主键),标准价格,说明。

发票和顾客之间的关系是多对1。

一发票可以涉及仅一个客户,而一个客户可以涉及任何数量的发票。

发票和产品之间的关系是许多对多。

任何数量的产品可以被放置在一发票,和一个CM产品可以出现在不同的发票。

发票和产品之间的关系有两个属性:SellPrice 和数量。

化E-R为代码1除了日期是date类型,其他都可以用varchar(20),类型写在后2 #叫_Number3注意格式,括号,逗号4主码一定要前面罗列一次,后面再总结是主码一次。

外码也是。

有一种情况是描述联系集时,来自两个实体集的主码同时也是外码。

(2) create table Invoice(Invoice_Number char(10),TotalOrderAmt integer,Invoice_Date date,Terms char(30),ShipVia char(20),Cust_Number char(10),(对方的主码——外码)Primary key(Invoice_Number),(主码描述)Foreign key(Cust_Number) references Customer)(外码描述)Create table Customer(Cust_Number char(10),CName char(10),Street char(30),City char(10),State char(10),Zip char(10),Phone char(20),Primary key(Cust_Number))Create table Product(Prod_Number char(10),StandardPrice number,Description char(30),Primary key(Prod_Number))Create table LineItem(Invoice_Number char(10),Prod_Number char(10),SellPrice number,Quantity number,Primary key(Invoice_Number, Prod_Number)(主码是来自两个实体集的主码,同时也是外码)Foreign key(Invoice_Number) references Invoice,Foreign key(Prod_Number) references Product)化文字描述为E-R图Question 3 [12 marks] There are 3 entities into database of an enterprise. Entity Store is associated with store number, store name and address etc. Entity commodity(商品)is associated with commodity number, commodity name, specification and price. Entity employee(员工)is associated with employee no, employee name, sex and performance. Each commodity can be sold in many stores and each store may sold many kinds of commodity. For each commodity in a certain store, the sale quantity must be recorded per month. For each store, there are many employees. For each employee, he can works for only one store. For each employee who works in a certain store, salary and work period must be recorded.(1) Draw ER diagram to illustrate the requirements. And you can make and state necessary assumptions if any. [6 marks](2) Translate your ER diagram into relational database schemas, underline primary keys of each relation, and label foreign keys if it has. Be sure using different way to mark primary keys and foreign keys. [6 marks]问题3 [12标记〕有3个实体到一个企业数据库。

实体店与店号,店名和地址等实体商品与商品号,商品名称,规格和价格的关联。

实体员工与员工没有,员工,性别和性能有关。

每种商品可以在很多商店销售,每家店可能销售的多种商品。

对于在某些商店每一件商品,销售数量必须每月进行记录。

对于每一个商店,有很多员工。

对于每一个员工,他的作品只有一家门店。

公司为每位员工谁在某个店里工作,工资和工作时间必须记录。

(1)画出ER图来说明的要求。

你可以做,如果任何国家必要的假设。

[6商标〕(2)翻译的ER图到关系数据库模式,背后的每个关系的主键和标签外键,如果有。

请务必在使用不同的方式来纪念主键和外键。

[6商标〕Question 3 [12 marks](1) Draw ER diagram to illustrate the requirements. And you can make and state necessary assumptions if any. [6 marks](2) Translate your ER diagram into relational database schemas, underline primary keys of each relation, and label foreign keys if it has. Be sure using different way to mark primary keys and foreign keys. [6 marks] 化文字描述为伪代码注意英文词语要规。

根据上文,下划线联系集要写明外码来自于哪里。

相关主题