[理学]南开大学数据库原理课件lecture2-Relational Data Model
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Instances
• Relational schema = R(A1,…,Ak): Instance = relation with k attributes (of “type” R)
– values of corresponding domains
• Database schema = R1(…), R2(…), …, Rn(…) Instance = n relations, of types R1, R2, ..., Rn
3
2009 Xiaojie Yuan
An Example of a Relation
Table name
Products: Name
Price
Attribute names
Category
Manufacturer
gizmo
$19.99
gadgets
GizmoWorks
Power gizmo $29.99
• Relational model
– has just a single concept: relation – world is represented with a collection of tables – well-suited for efficient manipulations on computers
Name
Price
Category
Manufacturer
gizmo
$19.99
gadgets
GizmoWorks
Power gizmo $29.99
gadgets
GizmoWorks
SingleTouch $149.99 photography Canon
MultiTouch $203.99 household Hitachi
Updates to the data happen very frequently.
Updates to the schema: relatively rare. Rather painful. Why?
9
2009 Xiaojie Yuan
Schemas and Instances
• Analogy with programming languages:
Relational Schema
Physical storage
Diagrቤተ መጻሕፍቲ ባይዱms (E/R)
Tables: column names: attributes rows: tuples
Complex file organization and index structures.
2
2009 Xiaojie Yuan
– Schema = type – Instance = value
• Important distinction:
– Database Schema = stable over long periods of time
Schemas vs. instances (very important, make sure you know the difference)
7
2009 Xiaojie Yuan
Example
Relational schema:Product(Name, Price, Category, Manufacturer) Instance:
The Relational Data Model
• Tables • Schemas • Conversion from E/R to Relations
1
2009 Xiaojie Yuan
Database Modeling & Implementation
Ideas
Database Model (E/R, ODL)
ER Model vs. Relational Model
• Both are used to model data • ER model has many concepts
– entities, relations, attributes, etc. – well-suited for capturing the app. requirements – not well-suited for computer implementation – (does not even have operations on its structures)
The Schema of a Database
– A set of relation schemas – E.g. Product(Name, Price, Category, Manufacturer),
Vendor(Name, Address, Phone), .......
6
2009 Xiaojie Yuan
8
2009 Xiaojie Yuan
Updates
The database maintains a current database state.
Updates to the data:
1) add a tuple 2) delete a tuple 3) modify an attribute in a tuple
– Integer – String – Real –…
5
2009 Xiaojie Yuan
Schemas
The Schema of a Relation:
– Relation name plus attribute names – E.g. Product(Name, Price, Category, Manufacturer) – In practice we add the domain for each attribute
gadgets
GizmoWorks
SingleTouch $149.99 photography Canon
MultiTouch $203.99 household Hitachi
tuples
4
2009 Xiaojie Yuan
Domains
• Each attribute has a type • Must be atomic type (why? see later) • Called domain • Examples: