haihongyuan.com
海量文库 文档专家
全站搜索:
您现在的位置:首页 > 初中教育 > 科学科学

lecture2-Relational+Data+Model

发布时间:2014-04-17 14:20:23  

The Relational Data Model
? Tables ? Schemas ? Conversion from E/R to Relations

1
?2012 Xiaojie Yuan

Database Modeling & Implementation
Ideas Database Model (E/R, ODL) Relational Schema Physical storage

Diagrams (E/R)

Tables: column names: attributes rows: tuples

Complex file organization and index structures.
2
?2012 Xiaojie Yuan

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)

? Relational model
– has just a single concept: relation – world is represented with a collection of tables – well-suited for efficient manipulations on computers
3
?2012 Xiaojie Yuan

An Example of a Relation
Table name Products: Name gizmo Price $19.99 Attribute names Category gadgets gadgets Manufacturer GizmoWorks GizmoWorks

Power gizmo $29.99

SingleTouch $149.99
MultiTouch $203.99

photography
household

Canon
Hitachi

tuples

4
?2012 Xiaojie Yuan

Domains
? ? ? ? Each attribute has a type Must be atomic type (why? see later) Called domain Examples:
– Integer – String – Real –…
5
?2012 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

The Schema of a Database
– A set of relation schemas – E.g. Product(Name, Price, Category, Manufacturer), Vendor(Name, Address, Phone), .......
6
?2012 Xiaojie Yuan

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 Schemas vs. instances (very important, make sure you know the difference)
7
?2012 Xiaojie Yuan

Example
Relational schema:Product(Name, Price, Category, Manufacturer) Instance: Name Price Category Manufacturer

gizmo

$19.99

gadgets
gadgets photography household

GizmoWorks
GizmoWorks Canon Hitachi
8
?2012 Xiaojie Yuan

Power gizmo $29.99 SingleTouch $149.99 MultiTouch $203.99

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 Updates to the data happen very frequently.
Updates to the schema: relatively rare. Rather painful. Why?
9
?2012 Xiaojie Yuan

Schemas and Instances
? Analogy with programming languages:
– Schema = type – Instance = value

? Important distinction:
– Database Schema = stable over long periods of time – Database Instance = changes constantly, as data is inserted/updated/deleted
10
?2012 Xiaojie Yuan

Two Mathematical Definitions of Relations
Relation as Cartesian product ? Tuple = element of string x int x string x string ? E.g. t = (gizmo, 19, gadgets,

网站首页网站地图 站长统计
All rights reserved Powered by 海文库
copyright ©right 2010-2011。
文档资料库内容来自网络,如有侵犯请联系客服。zhit326@126.com