Presentation is loading. Please wait.

Presentation is loading. Please wait.

IST 220 – Intro to Databases Lecture 3 Database Design Guidelines.

Similar presentations


Presentation on theme: "IST 220 – Intro to Databases Lecture 3 Database Design Guidelines."— Presentation transcript:

1 IST 220 – Intro to Databases Lecture 3 Database Design Guidelines

2 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 To provide various ways to view (on the screen or in print) the data in the database In a relational database, data is stored in a number of tables

3 A Sample Application – A Library

4 DB In A Flat File Problems for DB’s with one BIG table Unnecessary 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 manipulate The library table contains information about Books Authors Publishers Book-author (relationship)

5 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 books AUTHORS – 1 record for each of the 13 authors PUBLISHERS – only three publishers! BOOK_AUTHOR Some authors have published more than one book Some books are co-authored by more than one person

6 Tables For The Three Entities PubIDPubNamePubNumber 1Big House123-455-7890 2Alpha Press999-990-9999 3Small House714-000-0000 AuIDAuNameAuPhone 1Austen111-111-1111 12Grumpy321-321-0000 3Homer333-333-3333 10Jones123-333-3333 6Joyce066-666-6066 2Melville222-222-2222 8Mill858-688-8888 4Roman444-444-4444 5Shakespeare555-555-5555 13Sleepy321-321-1111 9Smith123-222-2222 11Snoopy321-321-2222 7Spenser777-777-7777 ISBNTitlePubIDPrice 0-555-55555-9Macbeth2$12.00 0-91-335678-7Faerie Queene1$15.00 0-99-909999-9Emma1$20.00 0-91-045678-5Hamlet2$20.00 0-55-123456-9Main Street3$22.95 1-22-233100-0Visual Basic1$25.00 0-12-333433-3On Liberty1$25.00 0-103-45678-9Iliad1$25.00 1-1111-1111-1C++1$29.95 0-321-32132-1Balloon3$34.00 0-123-45678-0Ulysses2$3400 0-90-777777-7King Lear2$49.00 0-12-345678-9Jane Eyre3$49.00 0-12-345678-9Moby-Dick3$49.00

7 The Table For The Relationship ISBNAuID 0-103-45678-93 0-11-345678-02 0-12-345678-98 1 0-123-45678-06 0-321-32132-111 0-321-32132-112 0-321-32132-113 0-55-123456-99 10 0-555-55555-95 0-91-045678-55 0-91-335678-77 0-99-777777-75 0-99-999999-91 1-1111-1111-14 1-22-233700-04 One book with three co-authors One author with three books

8 Complications Of RDB Design Avoiding data loss during decomposition Each attribute should be included in at least one table Maintaining relational integrity Defining and implementing relationship between tables correctly Some attributes will show up in more than one tables

9 Complications Of RDB Design Creating views Gathering data from more than one table when needed Example Display a list of all publishers that publish books priced under $20.00 – need to access BOOKS and PUBLISHERS tables

10 Entity & Entity Set Entities: real-world objects or concepts Entity set: a set of entities sharing the same properties (or attributes) Examples Entity sets: books, authors, publishers Attributes: author id ( AuID ), author name ( AuName ), and author phone ( AuPhone ) Entities: Austen, Grumpy, Homer, etc

11 Relationship & Relationship Set Relationship – an association among entities Relationship set – a set of relationships of the same type Example Relationship set: book-author Relationship: Macbeth-Shakespeare, Iliad- Homer

12 Relationship Among Tables PubIDPubNamePubNumber AuIDAuNameAuPhone ISBNTitlePubIDPrice ISBNAuID BOOKS PUBLISHERS AUTHORS BOOK-AUTHOR

13 An Example 0-555-55555-9Macbeth2$12.00 5Shakespeare555-555-5555 0-555-55555-95 2Alpha Press999-990-9999 AUTHORS BOOK-AUTHOR BOOKS PUBLISHERS

14 DB Design Rules – I Compound attributes An attribute which is made up by a few parts Examples Name = first-name + last-name Address = 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

15 DB Design Rules – II Primary key A primary key is one or more attributes which can uniquely identify records in a table Examples ISBN in the BOOKS table ISBN and AuID in the BOOK-AUTHOR table Rule 2: Primary Keys Each table should have a primary key (PK)

16 Foreign Keys An attribute is referred as a foreign key (FK) if it is used as a primary key in another table Example: PubID in the BOOKS table – FK PubID 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

17 PK & FK

18 Cardinality Constraints PubIDPubNamePubNumber AuIDAuNameAuPhone ISBNTitlePubIDPrice ISBNAuID BOOKS PUBLISHERS AUTHORS BOOK-AUTHOR 1 n 1 1 n n

19 DB Design Rules – III Functional dependence A property that each attribute in a table is determined by the PK Satisfy: a book name is known for a given ISBN Violate: in the flat table, a publisher’s phone may change regardless what the ISBN is Rule 3: Functional Dependence For each unique PK value, other attributes must be relevant to, and must completely describe the subject of the table

20 DB Design Rules – IV Rule 4: Field Independence You 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.


Download ppt "IST 220 – Intro to Databases Lecture 3 Database Design Guidelines."

Similar presentations


Ads by Google