Chapter Four Database Design (Relational) Objectives Summary Keys (Constraints) Relational DBMS Normal Forms.

Slides:



Advertisements
Similar presentations
Chapter 6: Entity-Relationship Model (part I)
Advertisements

Functional Dependencies and Normalization for Relational Databases
Chapter Three Objectives Identification of Keys Application of primary and foreign keys Converting a database design to Relational DB. What is a good DBMS.
ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala N ATIONAL I NSTITUTE OF T ECHNOLOGY A GARTALA Aug-Dec,2010 Normalization 2 CSE-503 :: D ATABASE.
© 2002 by Prentice Hall 1 SI 654 Database Application Design Winter 2003 Dragomir R. Radev.
1/22/20091 Study the methods of first, second, third, Boyce-Codd, fourth and fifth normal form for relational database design, in order to eliminate data.
Chapter 3 : Relational Model
Relational Model (CB Chapter 4) CPSC 356 Database Ellen Walker Hiram College.
Normalization Dr. Mario Guimaraes. Data Normalization Primarily a tool to validate and improve a logical design so that it satisfies certain constraints.
The Relational Model System Development Life Cycle Normalisation
1 Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Information Resources Management February 13, 2001.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
Database Architecture The Relational Database Model.
Introduction to Schema Refinement
DATA NORMALISATION Pamela Quick. Data Normalisation 2 Objectives  Data normalisation aims to derive record structures which avoid anomalies in u Insertion.
Module Title? DBMS E-R Model to Relational Model.
1 Normalization, Roberts’s Rules and Introduction to Data Modeling CSCI 6442.
Web-Enabled Decision Support Systems
Chapter One (Introduction) Objectives Introduction to Database Management Systems (DBMS) Relational Databases Model Restrictions of RD Database Life Cycle.
Concepts and Terminology Introduction to Database.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
NormalizationNormalization Chapter 4. Purpose of Normalization Normalization  A technique for producing a set of relations with desirable properties,
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Lecture9:Functional Dependencies and Normalization for Relational Databases Prepared by L. Nouf Almujally Ref. Chapter Lecture9 1.
CS143 Review: Normalization Theory Q: Is it a good table design? We can start with an ER diagram or with a large relation that contain a sample of the.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, Modified by Dr. Mathis 3-1 David M. Kroenke’s Chapter Three: The Relational.
CSC271 Database Systems Lecture # 28.
1 Normalization, Roberts’s Rules and Introduction to Data Modeling CSCI 6442.
1 Normalization, Roberts’s Rules and Introduction to Data Modeling CSCI 6442.
Normalization Ioan Despi 2 The basic objective of logical modeling: to develop a “good” description of the data, its relationships and its constraints.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
IE 423 – Design of Decision Support Systems Data modeling and database development.
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Data modeling using the entity-relationship model Chapter 3 Objectives How entities, tuples, attributes and relationships among entities are represented.
1 Functional Dependencies and Normalization Chapter 15.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Chapter Three ( Relational Data Model) Objectives Introduction to Relational Data Models. Advantages of Relational Data Models. Restriction of Relational.
Lecture9:Functional Dependencies and Normalization for Relational Databases Ref. Chapter Lecture9 1.
Dr. Mohamed Osman Hegaz1 Logical data base design (2) Normalization.
Relational Model E.F. Codd at IBM 1970 Chapter 3 (ed. 7 – Chap. 5)
Normalization.
Chapter 5.1 and 5.2 Brian Cobarrubia Database Management Systems II January 31, 2008.
The Normal Forms 3NF and BCNF
NORMALIZATION. What is Normalization  The process of effectively organizing data in a database  Two goals  To eliminate redundant data  Ensure data.
Logical Database Design and the Relational Model.
Lecture 4: Logical Database Design and the Relational Model 1.
11/06/97J-1 Principles of Relational Design Chapter 12.
Objectives of Normalization  To create a formal framework for analyzing relation schemas based on their keys and on the functional dependencies among.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
4NF & MULTIVALUED DEPENDENCY By Kristina Miguel. Review  Superkey – a set of attributes which will uniquely identify each tuple in a relation  Candidate.
4TH NORMAL FORM By: Karen McVay.
Revised: 2 April 2004 Fred Swartz
Normalization DBMS.
Normalization Dongsheng Lu Feb 21, 2003.
Chapter 5: Logical Database Design and the Relational Model
Relational Database Design by Dr. S. Sridhar, Ph. D
Payroll Management System
A SIMPLE GUIDE TO FIVE NORMAL FORMS (See the next slide for required reading) Prof. Ghandeharizadeh 2018/11/14.
Relational Database.
Normalization.
Database Normalization
Normalization.
Normalization Dongsheng Lu Feb 21, 2003.
Chapter 7 Normalization Chapter 13 in Textbook.
Normalization Dale-Marie Wilson, Ph.D..
4 Normal Form.
Functional Dependencies and Normalization
Presentation transcript:

Chapter Four Database Design (Relational) Objectives Summary Keys (Constraints) Relational DBMS Normal Forms

2 Summary DB Lifecycle Business Requirements Design (ER) Build DB Production Architecture of DBMS Definitions Data Models Database Design (ER Model) Strong Entity Weak Entity Relationship Functionality Functional Dependency

3 Keys (Constraints) A set of attributes whose values uniquely identify each entity in an entity set or a relationship set How do we identify keys? Relation R with a 1, a 2, … a n

4 Keys (Constraints) 1. Super key: Any set of attributes that uniquely identify each table. Student (Name, ID, GPA, Major, Minor, Address, Phone)

5 Keys (Constraints) 2. Candidate Key: Smallest super key 3. Primary key: Candidate key selected by the DBA

6 Keys (Constraints) Characteristic of primary key: a. Uniqueness: At any given time, no two tuples can have the same value for a given primary key b. Minimally: None of the attributes in the primary key can be discarded without distorting the uniqueness property

7 Keys (Constraints) 4. Foreign Key: An attribute(s) in an entity set one (relation one) which is the primary key of entity two(relation two) R 1 (a,b,c,d,e) R 2 (x,y,z,a,w) Faculty (ID, Name, Salary, D_name, age, Hiring_date) Department(D_name, No_Faculty, D_head)

Relational DBMS

9 RDBM: Data are represented as a set of tables (relation is a mathematical term for a table) Originated by E.F. Codd(1970) Based on sets theory Record base data model

10 Structure: A set of relations (Table) Each relation has a unique name Each relation has a set of attributes (Columns) Each relation has a set of tuples (Rows)

11 Degree of a Relation: Number of attributes in a relation: Relation with one attribute is called Unary Relation with two attributes is called Binary Relation with three attributes is called Ternary Relation with n attributes is called n-ary

12 Cardinality of a relation Number of tuples

13 Restriction on RDB: No two tuples are the same No two attributes are the same The order of tuples are immaterial The order of attributes are immaterial There is an attribute or collection of attributes which identifies tuples uniquely called Primary Key Value of attribute must be atomic

14 Ra1a1 a2a2 …… anan T1 T2 R: Relation Name a n : attribute T m : tuple T[a n ]: value of attributes for tuple T Intention vs. Extension

15 Converting E.R Diagram to Relational 1. Strong Entity sets: Let E be a strong entity set with attributes a 1, a 2,a 3, … a n Create a relation R with n distinct columns each of which corresponds to one of the attributes in E

16 Converting E.R Diagram to Relational 2. Weak Entity sets: Let W be a weak entity set with attributes a 1,a 2,a 3, … a k Let E be the strong entity set on which W is dependent Let primary key of E be e 1,e 2,e 3, … e x Create a relation R with k+x columns (a 1, a 2,a 3, … a m ) & (e 1,e 2,e 3, … e x )

17 Converting E.R Diagram to Relational 3. Relationship: Let R be a relationship among entity sets e 1, e 2, … e n with primary keys (E i ) and attributes a 1 … a n Create a relation called R with U n Primary key (E i ) U {a 1, … a n }

18 Example Convert the school ER diagram into relational database.

19 Normal Forms (Guidelines for RD design) How do we know this design is good? If it is not a good design, What should we do? Modify our design ??.

20 Normal Forms (Guidelines for RD design) First Normal Form (1NF) Deals with the shape of the records A relation is in 1NF if the values of domain is atomic for each attribute.

21 First Normal Form: 1NF Example: R (A, B, C, … ) R ( A B )R ( AB ) a1b1, b2=>a1b1 a1b2

22 First Normal Form: 1NF Example: Person (NameAgeChildren) Smith42John, Lori, Mark Person (NameAgeChild) Smith42John Smith42Lori Smith42Mark

23 First Normal Form: 1NF Example: Student (NameBirthday) S1Feb 2,91 S2March 8,88 Student (Name, D_Birth, M_Birth, Y_Birth) Note: 2NF and 3NF Deal with the relationship between non-key and key

24 Second Normal Form: 2NF A relation R is in 2NF with respect to a set of FD if it is in 1NF and every non- prime attribute is Fully dependent on the entire key in R. Fact: 2NF is violated when a non-key is a fact about a subset of a primary key

25 Second Normal Form: 2NF Non-prime vs. prime: A relation R with attribute A and a set of FD on attribute A is prime if A is contained in some key of R, otherwise A is non-prime

26 Second Normal Form: 2NF Example: R(A,B,C,D) with FD A, B ---> C, D A ---> D D partially depends on A,B C fully depends on A,B A&B are prime (part of key) If A is primary key. Is this in 2NF? If A&B is primary key. Is this in 2NF?

27 Second Normal Form: 2NF What should we do with a relation which is not in 2NF? Example: R(A,B,C,D) A, B ---> C, D A ---> D R1 (A,B,C) R2(A,D)

28 Second Normal Form: 2NF Example: R(PartWarehouseAddressQuantity) P1W1Frostburg25 P2W1Frostburg30 P3W2Cumberland32 P4W4Frostburg25 P4W1 What is the primary key? Part, Warehouse ---> Quantity Warehouse ---> Address

29 Second Normal Form: 2NF Problems: 1. Repetition of information: Changing the address W! 2. Unable to present information: Warehouse with no part 3. Inconsistency So … R1 (Warehouse, Address) R2 (Part, Warehouse, Quantity)

30 Second Normal Form: 2NF Example: R(Professor,Student,Course,Degree) P1S1C1Ph.D. P2S2C2M.S. P3S2C4M.S. P3S3C4Pg.D. Professor ---> Course Student ---> Degree Professor ---> Student Key? Not in 2NF R1(Student, Degree) R2(Professor, Course, Student)

31  A relation R is 3NF with respect to a set of FD if it is in 2NF and whenever A ---> B holds, then 1.A --> B is a trivial FD 2.A is a superkey for R 3.B is contained in a candidate key for R  A Non-key attribute non transitively depends on the Primary Key. Third Normal Form (3NF):

32 Third Normal Form (3NF):  Example: R(A,B,C,D) A, B --->DR1(A,B,D) D ---> CR2(D,C) Fact: 3NF is violated when a non-key is a fact about another non-key Employee ---> Dept ---> Location

33 Third Normal Form (3NF): Example: R(Employee, Dept, Location) Employee ---> Dept Dept ---> Location EmployeeDeptLocation E1D1Frostburg E2D1Frostburg E3D1Frostburg Problems? R1(Employee, Dept) R2(Dept, Location)

34 Third Normal Form (3NF): ItemInfo (item,price, discount) Item ---> price Price ---> discount Item price discount I1.992% I2.802% I3.102% I4510%

35 Third Normal Form (3NF): Employee (ID, Name, Expertise,Age, Dept) ID --> Name ID --> Expertise ID --> Age ID --> Dept Dept --> Expertise

36 Third Normal Form (3NF): Example: R(A,B,C,D) A,B ---> C A,C ---> D So A,B is the Primary Key Not in 3NF R1(A,B,C) R2(A,C,D)

37 Boyce Codd Normal Form: Def: A relation schema R is in BCNF with respect to a set of FD, if it is 3NF and whenever X  A holds, then X is a superkey (A  X)

38 Boyce Codd Normal Form: Most 3 rd NF relations are also BCNF A 3 rd NF relation is NOT in BCNF if: Candidate keys in the relation are composite keys (not single attribute) There is more than one candidate key in the relation, and The keys are not disjoint (some attributes in the keys are common)

39 Boyce Codd Normal Form: A relation is in BCNF if every determinant is a candidate key R(A,B,C) FD: A,B -> C C -> A A is prime, so it is 3 rd NF C is not candidate key (Not in BCNF) Not BCNFR1(A,B,C) R2(A,C)

40 Boyce Codd Normal Form: S(SupplierNo, sname, status, city) FD: SupplierNo ---> status SupplierNo ---> city SupplierNo ---> sname sname ---> status sname ---> city sname ---> SupplierNo It is in BCNF; Every determinate is a candidate key

41 Boyce Codd Normal Form: S(SupplierNosnameStatusCity) S1SmithHFrostburg S2JohnsonLLaVale S3MarkerMCumberla nd

42 Boyce Codd Normal Form: S(SupplierNo, sname, PartNo, Qty) FD: SupplierNo --  sname SupplierNo, PartNo ---> Qty sname, PartNo ---> Qty

43 Boyce Codd Normal Form: S(SupplierNosnamePartNoQty) S1SmithP1100 S1SmithP2200 S1SmithP3300 S1SmithP4400 It is in 3NF; not in BCNF; Problems: Sname or SupplierNo are not candidate keys for this relation R1(SupplierNo, sname) R2(sname, PartNo, Qty)

44 Boyce Codd Normal Form: ClientInterview (ClientNo, InterviewDate, InterviewTime, StaffID, roomNo) ClientNo,InterviewDate -> InterviewTime ClientNo, InterviewDate -> StaffID ClientNo, InterviewDate -> RoomNo Staffid, InterviewDate, InterviewTime -> ClientNo RoomNo, InterviewDate, InterviewTime -> StaffID RoomNo, InterviewDate, InterviewTime -> ClientNo StaffID, InterviewDate -> RoomNo

45 Boyce Codd Normal Form: ClientNoInterviewDateInterviewTimeStaffIDRoomNo C25March 2, 0210:00S10GC104 C28March 2, 0211:30S10GC104 C72March 2, 021:30S8GC103 C28April 2, 0210:00S24GC103 It is in 3NF Not in BCNF (StaffID, InterviewData) is not a cadidatekey

46 Boyce Codd Normal Form: R1(ClientNo, InterviewData, InterviewTime, StaffID) R2(StaffID,InterviewData, RoomNo)

47 Normal Forms: Cars(Model, NoCylinders, Madeln, Tax, Fee) Model, NoCylinders ---> Madeln Model, NoCylinders ---> Tax Model, NoCylinders ---> Fee NoCylinders ---> Fee Madeln ---> Tax

48 Normal Forms: Cars(ModelNoCylindersMadelnTaxFee) GM6U.S.$20$30 Toyota4Japan$40$5 Honda4Japan$40$5 VW5German$50$10 Primary Key? Model, NoCylinders  Is it in 1NF?  Is it in 2NF?

49 Normal Forms: Cars(Model, NoCylinders, Madeln, Tax) Licensing(NoCylinders,Fee)

50 Normal Forms: Is it in 3NF? Cars(Model, NoCylinders, Madeln) Taxation(Madeln, Tax) Licensing(NoCylinders, Fee) Assume we have FD Madeln ---> NoCylinders It is not in BCNF Cars(Model, NoCylinders) EngineSize(NoCylinders, Madeln)

51 Practice: A: PropertyNo B: PropertyAddress C: InspectionDate D: InspectionTime E: Comments F: StaffID G: StaffName H: CarRegistrationNo FD: A,C -> D,E,F,G,H A -> B F -> G F,C -> H H,C,D -> A,B,E,F,G F,C,D -> A,B,E

52 Multivalue Dependency (MVD) Multi valued Dependency are a generalization of FD Relation R, with x,y subset attributes of of R we say X -->-> Y There is a multivalued dependency of y on x. Given a value for x there is a set of values for y.

53 Multivalue Dependency (MVD) Example: Name --->->St, city SS1 C1 SS2 C2 MS1 C1 MS2 C2

54 Multi-value Dependency (MVD) Rx y R-x-y t s U V x--->->y hold if t and s are 2 tuples in R t[x]=s[x] then also there are tuples u and v where 1.u[x]=v[x]=t[x]=s[x] 2.u[y]=t[y] & u[R-x-y]=S[R-x-y] 3.v[y]=s[y] & v[R-x-y]=t[R-x-y] [Relationship between x&y is independent of the relationship between x & R-y]

55 Example: Multivalue Dependency (MVD) NameStCityCar tSS1C1Ford sSS2C2Chev uSS1C1Chev vSS2C2Ford 1.u[Name]=v[Name]=s[Name]=t[Name] 2.u[St,City]=t[St,City] & u[Car]=s[Car] 3.v[St,City]=s[St,City] & v[Car]=t[Car]

56 Fourth Normal Form (4NF): A relation is in 4 th NF with respect to a set of MVD. If it is in 3 rd NF and whenever x--->->y holds, then x in a superkey (x--->->y is not a trivial multivalued dependency, that is y  x; y  xy or x not empty) 4NF is violated when a record type contains two or more independent multivalued facts about an entity. 4 th and 5 th NF in a sense are also about composite keys

57 Fourth Normal Form (4NF): Example: R(Employee, Skill, Language) Employee  Skill Employee  Language

58 Fourth Normal Form (4NF): Example: R(Employee, Skill, Language) EmployeeSkillLanguage E1Cook E1Cashier E1Manager E1English E1German E1Italian E2CookGerman

59 Fourth Normal Form (4NF): We have two, many-to-many relationships, Employee and Skill Employee and Language Employee --->-> Skill R1(Employee, Skill) R2(Employee, Language)

60 Fourth Normal Form (4NF): EmployeeSkill E1Cook E1Cashier E1Manager E2Cook EmployeeLanguage E1English E1German E1Italian E2German

61 Fourth Normal Form (4NF): IN 4 Th normal form a record should not contain two or more independent multi- valued fact about an entity

62 Join Dependency (5 NF) R(SupplierNoPartNoProjectNo) S1P1N2 S2P2N1 S2P1N1 S1P1N1 R1(SupplierNoPartNo ) S1P1 S1P2 S2P1 R2(PartNoProjectNo ) P1N2 P2N1 P1N1

63 Join Dependency R3(SupplierNoProject No ) S1N2 S1N1 S2N1

64 Join Dependency Join R1 & R2 over PartNo SupplierNoPartNoProjectNo S1P1N2 S1P2N1 S2P1N1 S2P1N2 S1P1N1

65 Join Dependency Join Result with R3 SupplierNoPartNoProjectNo S1P1N2 S1P2N1 S2 P1 N1 S1P1N1

66 Join Dependency If(S1,P1) appears in R1 AND (P1,N1) appears in R2 AND (N1,S1) appears in R3 THEN (S1,P1,N1) appears in R Rewrite: IF (S1,P1,N2), (S2,P1,N1), (S1,P2,N1) appears in R THEN (S1,P1,N1) appear in R

67 Join Dependency Example: IF Nelson supplies Screw Driver AND Screw Drivers are used in Pullen project AND Nelson supplies the Pullen project THEN Nelson supplies Screw Drivers for Pullen project

68 Fifth Normal Form (5NF): 5 th normal form deals with cases that information can be reconstructed from smaller pieces of information which can be maintained with less redundancy. Join Dependency If an agent represents a company; and company makes a product and agent sales product, so we have: R(AgentCompanyProduct) A1FordCar A1GMTruck

69 Fifth Normal Form (5NF): Lets assume, there is a rule: “ if an agent sells a product and s/he represent the company making that product, then s/he sells that product for that company ”. AgentCompanyProduct S1Fordcar S1FordTruck S1GMCar S1GMTruck S2FordCar

70 Fifth Normal Form (5NF): AgentCompany S1Ford S1GM S2Ford CompanyProducts FordCar FordTruck GMCar GMTruck AgentProducts S1Car S1Truck S2Car