Introduction to Database Systems-Lecture 03 Slides-Computer Science, Slides of Introduction to Database Management Systems

Relational Database Design, Relational Model, Keys, Schema Vs. Data, Usage of Keys, Look up, Pointers, Database Design, Entity-relationship Model, E/R Basics, Attributes of Relationships, Multiplicity of Relationships, N-ary Relationships, N-ary Versus Binary Relationships, Roles in Relationships, Weak Entity Sets, Many-one, One-one, Modeling N-ary Relationships, ISA Relationships, Redundancy, Reference

Typology: Slides

2011/2012

Uploaded on 01/29/2012

arold
arold šŸ‡ŗšŸ‡ø

4.7

(24)

372 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Relational Database Design
Part I
CPS 116
Introduction to Database Systems
2
Announcement
īš™DB2 accounts created; change your password!
Let me know if you have NOT received the email
īš™Pick up Gradiance registration information sheet at
the end of this lecture
īš™Homework #1 out today
Due next Thursday (September 9) at 11:59pm
)Start early!
3
Relational model: review
īš™A database is a collection of relations (or tables)
īš™Each relation has a list of attributes (or columns)
īš™Each attribute has a domain (or type)
īš™Each relation contains a set of tuples (or rows)
4
Keys
īš™A set of attributes Kis a key for a relation Rif
In no instance of Rwill two different tuples agree on all
attributes of K
•That is, Kis a ā€œtuple identifierā€
No proper subset of Ksatisfies the above condition
•That is, Kis minimal
īš™Example: Student (SID, name, age, GPA)
SID is a key of Student
age is not a key (not an identifier)
{SID, name} is not a key (not minimal)
5
Schema vs. data
īš™Is name a key of Student?
Yes? Seems reasonable for this instance
No! Student names are not unique in general
īš™Key declarations are part of the schema
Student
SID name age GPA
142 Bart 10 2.3
123 Milhouse 10 3.1
857 Lisa 8 4.3
456 Ralph 8 2.3
6
More examples of keys
īš™Enroll (SID, CID)
{SID, CID}
īš™Address (street_address, city, state, zip)
{street_address, city, state}
{street_address, zip}
pf3
pf4
pf5

Partial preview of the text

Download Introduction to Database Systems-Lecture 03 Slides-Computer Science and more Slides Introduction to Database Management Systems in PDF only on Docsity!

Relational Database Design

Part I

CPS 116

Introduction to Database Systems

Announcement

Ā™ DB2 accounts created; change your password!

ƒ Let me know if you have NOT received the email

Ā™ Pick up Gradiance registration information sheet at

the end of this lecture

Ā™ Homework #1 out today

ƒ Due next Thursday (September 9) at 11:59pm

)Start early!

3

Relational model: review

Ā™ A database is a collection of relations (or tables)

Ā™ Each relation has a list of attributes (or columns)

Ā™ Each attribute has a domain (or type)

Ā™ Each relation contains a set of tuples (or rows)

4

Keys

Ā™ A set of attributes K is a key for a relation R if

ƒ In no instance of R will two different tuples agree on all

attributes of K

  • That is, K is a ā€œtuple identifierā€

ƒ No proper subset of K satisfies the above condition

  • That is, K is minimal

Ā™ Example: Student ( SID , name , age , GPA )

ƒ SID is a key of Student

ƒ age is not a key (not an identifier)

ƒ { SID , name } is not a key (not minimal)

5

Schema vs. data

Ā™ Is name a key of Student?

ƒ Yes? Seems reasonable for this instance

ƒ No! Student names are not unique in general

Ā™ Key declarations are part of the schema

Student SID 142 (^) name Bart (^) age 10 GPA 2. 123857 Milhouse 10Lisa 8 3.14. 456 Ralph 8 2.

6

More examples of keys

Ā™ Enroll ( SID , CID )

ƒ { SID , CID }

Ā™ Address ( street_address , city , state , zip )

ƒ { street_address , city , state }

ƒ { street_address , zip }

Usage of keys

Ā™ More constraints on data, fewer mistakes

Ā™ Look up a row by its key value

ƒ Many selection conditions are ā€œkey = valueā€

Ā™ ā€œPointersā€

ƒ Example: Enroll ( SID , CID )

  • SID is a key of Student
  • CID is a key of Course
  • An Enroll tuple ā€œlinksā€ a Student tuple with a Course tuple

ƒ Many join conditions are ā€œkey = key value stored in

another tableā€

Database design

Ā™ Understand the real-world domain being modeled

Ā™ Specify it using a database design model

ƒ Design models are especially convenient for schema

design, but are not necessarily implemented by DBMS

ƒ Popular ones include

  • Entity/Relationship (E/R) model
  • Object Definition Language (ODL)

Ā™ Translate specification to the data model of DBMS

ƒ Relational, XML, object-oriented, etc.

Ā™ Create DBMS schema

9

Entity-relationship (E/R) model

Ā™ Historically and still very popular

Ā™ Can think of as a ā€œwatered-downā€ object-oriented

design model

Ā™ E/R diagrams represent designs

Ā™ Primarily a design model—not implemented by any

major DBMS

10

E/R basics

Ā™ Entity: a ā€œthing,ā€ like a record or an object

Ā™ Entity set: a collection of things of the same type, like a

relation of tuples or a class of objects

ƒ Represented as a rectangle

Ā™ Relationship: an association among entities

Ā™ Relationship set: a set of relationships of the same type

(associations among same entity sets)

ƒ Represented as a diamond

Ā™ Attributes: properties of entities or relationships, like

attributes of tuples or objects

ƒ Represented as ovals

11

An example E/R diagram

Ā™ Students enroll in courses

Ā™ A key of an entity set is represented by underlining

all attributes in the key

ƒ A key is a set of attributes whose values can belong to at

most one entity in an entity set—like a key of a relation

nameSID^ Students^ Enroll Courses^ CIDtitle

12

Attributes of relationships

Ā™ Example: students take courses and receive grades

Students Courses CID title

SID Enroll name grade

Ā™ Where do the grades go?

ƒ With Students?

  • But a student can have different grades for multiple courses

ƒ With Courses?

  • But a course can assign different grades for multiple students

ƒ With Enroll!

Weak entity set examples

Ā™ Seats in rooms in buildings

Rooms In Buildings name year

number capacity In

Seats

number L/R?

Strictly speaking, the two arrows in this diagram should be rounded

Modeling n -ary relationships

Ā™ An n -ary relationship set can be replaced by a weak

entity set (called a connecting entity set) and n

binary relationship sets

Students Enroll Courses TA’s

TA’s

Students Enroll Courses

Note that the multiplicity constraint is lost

21

ISA relationships

Ā™ Similar to the idea of subclasses in object-oriented

programming: subclass = special case, more

properties, and fewer entities

ƒ Represented as a triangle (direction is important)

Ā™ Example: Graduate students are students, but they

also have offices

Students Courses CID title

SID Enroll name

office GradStudents

ISA

22

Summary of E/R concepts

Ā™ Entity sets

ƒ Keys

ƒ Weak entity sets

Ā™ Relationship sets

ƒ Attributes of relationships

ƒ Multiplicity

ƒ Roles

ƒ Binary versus N -ary relationships

  • Modeling N -ary relationships with weak entity sets and binary relationships

ƒ ISA relationships

23

Case study 1

Ā™ Design a database representing cities, counties, and states

ƒ For states, record name and capital (city) ƒ For counties, record name, area, and location (state) ƒ For cities, record name, population, and location (county and state)

Ā™ Assume the following:

ƒ Names of states are unique ƒ Names of counties are only unique within a state ƒ Names of cities are only unique within a county ƒ A city is always located in a single county ƒ A county is always located in a single state

24

Case study 1: first design

Ā™ County area information is repeated for every city in

the county

)Redundancy is bad (why?)

Ā™ State capital should really be a city

)ā€œReferenceā€ entities through explicit relationships

Cities In States

name capital

name population

county_area

county_name

Case study 1: second design

Ā™ Technically, nothing in this design could prevent a

city in state X from being the capital of another

state Y , but oh well…

Cities IsCapitalOf

name population

Counties

name area name

In In States

Case study 2

Ā™ Design a database consistent with the following:

ƒ A station has a unique name and an address, and is either

an express station or a local station

ƒ A train has a unique number and an engineer, and is

either an express train or a local train

ƒ A local train can stop at any station

ƒ An express train only stops at express stations

ƒ A train can stop at a station for any number of times

during a day

ƒ Train schedules are the same everyday

27

Case study 2: first design

Ā™ Nothing in this design prevents express trains from

stopping at local stations

)Capture all constraints if possible

Ā™ A train can stop at a station only once during a day

)Do not introduce constraints

Trains StopsAt Stations

name address

number

E/L?

engineer E/L? (^) time

28

Case study 2: second design

Trains Stations

name address

number engineer

time

ExpressTrains

LocalTrains LocalStations ExpressStations

ISA

LocalTrainStops ISA

time ExpressTrainStops Is the extra complexity worth it?