ist 220 – intro to databases
DESCRIPTION
IST 220 – Intro to Databases. Lecture 3 Database Design Guidelines. Recap – Database & DBMS. A database is a collection of related data A DBMS is a system that is designed for two main purposes To add, delete, and update the data in the database - PowerPoint PPT PresentationTRANSCRIPT
IST 220 – Intro to Databases
Lecture 3Database Design Guidelines
Recap – Database & DBMS
A database is a collection of related dataA DBMS is a system that is designed for
two main purposesTo add, delete, and update the data in the
databaseTo provide various ways to view (on the
screen or in print) the data in the databaseIn a relational database, data is stored in
a number of tables
A Sample Application – A Library
DB In A Flat File
Problems for DB’s with one BIG tableUnnecessary repetition (or redundancy)
Name and phone number of the Big House publishers repeated six times
Data about different real-world entities is messed up all together
Hard to maintain and manipulateThe library table contains information about
Books Authors Publishers Book-author (relationship)
DB In Related Tables
A solution is to break the big table down to a number of tables (decomposition)BOOKS – 1 record for each of the 14 booksAUTHORS – 1 record for each of the 13 authorsPUBLISHERS – only three publishers!
BOOK_AUTHOR Some authors have published more than one book Some books are co-authored by more than one person
Tables For The Three EntitiesPubID PubName PubNumber
1 Big House 123-455-7890
2 Alpha Press 999-990-9999
3 Small House 714-000-0000
AuID AuName AuPhone
1 Austen 111-111-1111
12 Grumpy 321-321-0000
3 Homer 333-333-3333
10 Jones 123-333-3333
6 Joyce 066-666-6066
2 Melville 222-222-2222
8 Mill 858-688-8888
4 Roman 444-444-4444
5 Shakespeare 555-555-5555
13 Sleepy 321-321-1111
9 Smith 123-222-2222
11 Snoopy 321-321-2222
7 Spenser 777-777-7777
ISBN Title PubID Price
0-555-55555-9 Macbeth 2 $12.00
0-91-335678-7 Faerie Queene 1 $15.00
0-99-909999-9 Emma 1 $20.00
0-91-045678-5 Hamlet 2 $20.00
0-55-123456-9 Main Street 3 $22.95
1-22-233100-0 Visual Basic 1 $25.00
0-12-333433-3 On Liberty 1 $25.00
0-103-45678-9 Iliad 1 $25.00
1-1111-1111-1 C++ 1 $29.95
0-321-32132-1 Balloon 3 $34.00
0-123-45678-0 Ulysses 2 $3400
0-90-777777-7 King Lear 2 $49.00
0-12-345678-9 Jane Eyre 3 $49.00
0-12-345678-9 Moby-Dick 3 $49.00
The Table For The RelationshipISBN AuID
0-103-45678-9 3
0-11-345678-0 2
0-12-345678-9 8
0-12-345678-9 1
0-123-45678-0 6
0-321-32132-1 11
0-321-32132-1
12
0-321-32132-1
13
0-55-123456-9
9
0-55-123456-9
10
0-555-55555-9 5
0-91-045678-5 5
0-91-335678-7 7
0-99-777777-7 5
0-99-999999-9 1
1-1111-1111-1 4
1-22-233700-0 4
One book with three co-authors
One author with three books
Complications Of RDB Design
Avoiding data loss during decompositionEach attribute should be included in at least
one tableMaintaining relational integrity
Defining and implementing relationship between tables correctly
Some attributes will show up in more than one tables
Complications Of RDB Design
Creating views Gathering data from more than one table
when neededExample
Display a list of all publishers that publish books priced under $20.00 – need to access BOOKS and PUBLISHERS tables
Entity & Entity Set
Entities: real-world objects or conceptsEntity set: a set of entities sharing the
same properties (or attributes)Examples
Entity sets: books, authors, publishersAttributes: author id (AuID), author name
(AuName), and author phone (AuPhone)Entities: Austen, Grumpy, Homer, etc
Relationship & Relationship Set
Relationship – an association among entitiesRelationship set – a set of relationships of
the same type Example
Relationship set: book-authorRelationship: Macbeth-Shakespeare, Iliad-
Homer
Relationship Among Tables
PubID PubName PubNumber
AuID AuName AuPhone
ISBN Title PubID Price
ISBN AuID
BOOKS
PUBLISHERS
AUTHORS
BOOK-AUTHOR
An Example
0-555-55555-9 Macbeth 2 $12.00
5 Shakespeare 555-555-5555
0-555-55555-9 5
2 Alpha Press 999-990-9999
AUTHORS
BOOK-AUTHOR
BOOKS
PUBLISHERS
DB Design Rules – I
Compound attributesAn attribute which is made up by a few partsExamples
Name = first-name + last-nameAddress = st number, st name, city, state, zip
Rule 1: Field Uniqueness Avoid using compound attributes Instead, use a number of attributes, each for
one of those parts
DB Design Rules – II
Primary key A primary key is one or more attributes which
can uniquely identify records in a tableExamples
ISBN in the BOOKS tableISBN and AuID in the BOOK-AUTHOR table
Rule 2: Primary Keys Each table should have a primary key (PK)
Foreign Keys
An attribute is referred as a foreign key (FK) if it is used as a primary key in another tableExample: PubID in the BOOKS table – FKPubID in the PUBLISHERS table – PK
FK’s are critical in linking the tables together
An attribute can be a foreign key and a part of the primary key at the same time
PK & FK
Cardinality Constraints
PubID PubName PubNumber
AuID AuName AuPhone
ISBN Title PubID Price
ISBN AuID
BOOKS
PUBLISHERS
AUTHORS
BOOK-AUTHOR1
n
1
1
n
n
DB Design Rules – III
Functional dependenceA property that each attribute in a table is
determined by the PK Satisfy: a book name is known for a given ISBNViolate: in the flat table, a publisher’s phone may
change regardless what the ISBN is
Rule 3: Functional DependenceFor each unique PK value, other attributes
must be relevant to, and must completely describe the subject of the table
DB Design Rules – IV
Rule 4: Field IndependenceYou must be able to make a change to the
data in any field (other than a field in the PK) without affecting the data in any other field
Example In the flat table, if you’ve mistaken the publisher
for the book 0-103-45678-9 (Iliad). When you want to change the publisher id, you have to change the associated name and phone attributes as well.