Download presentation

Presentation is loading. Please wait.

Published byKaden Cose Modified over 2 years ago

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

2
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
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
4 Keys (Constraints) 1. Super key: Any set of attributes that uniquely identify each table. Student (Name, ID, GPA, Major, Minor, Address, Phone)

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

6
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
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)

8
Relational DBMS

9
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
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
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
12 Cardinality of a relation Number of tuples

13
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
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
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
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
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
18 Example Convert the school ER diagram into relational database.

19
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
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
21 First Normal Form: 1NF Example: R (A, B, C, … ) R ( A B )R ( AB ) a1b1, b2=>a1b1 a1b2

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

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

29
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
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
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
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
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
34 Third Normal Form (3NF): ItemInfo (item,price, discount) Item ---> price Price ---> discount Item price discount I1.992% I2.802% I3.102% I4510%

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

36
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
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
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
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
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
41 Boyce Codd Normal Form: S(SupplierNosnameStatusCity) S1SmithHFrostburg S2JohnsonLLaVale S3MarkerMCumberla nd

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

43
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
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
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
46 Boyce Codd Normal Form: R1(ClientNo, InterviewData, InterviewTime, StaffID) R2(StaffID,InterviewData, RoomNo)

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

48
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
49 Normal Forms: Cars(Model, NoCylinders, Madeln, Tax) Licensing(NoCylinders,Fee)

50
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
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
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
53 Multivalue Dependency (MVD) Example: Name --->->St, city SS1 C1 SS2 C2 MS1 C1 MS2 C2

54
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
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
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
57 Fourth Normal Form (4NF): Example: R(Employee, Skill, Language) Employee Skill Employee Language

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

59
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
60 Fourth Normal Form (4NF): EmployeeSkill E1Cook E1Cashier E1Manager E2Cook EmployeeLanguage E1English E1German E1Italian E2German

61
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
62 Join Dependency (5 NF) R(SupplierNoPartNoProjectNo) S1P1N2 S2P2N1 S2P1N1 S1P1N1 R1(SupplierNoPartNo ) S1P1 S1P2 S2P1 R2(PartNoProjectNo ) P1N2 P2N1 P1N1

63
63 Join Dependency R3(SupplierNoProject No ) S1N2 S1N1 S2N1

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

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

66
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
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
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
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
70 Fifth Normal Form (5NF): AgentCompany S1Ford S1GM S2Ford CompanyProducts FordCar FordTruck GMCar GMTruck AgentProducts S1Car S1Truck S2Car

Similar presentations

OK

NORMALIZATION FIRST NORMAL FORM (1NF): A relation R is in 1NF if all attributes have atomic value = one value for an attribute = no repeating groups =

NORMALIZATION FIRST NORMAL FORM (1NF): A relation R is in 1NF if all attributes have atomic value = one value for an attribute = no repeating groups =

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on uses of plants for grade 1 Ppt on infosys company history Ppt on child labour free download in hindi Ppt on organisational structure Ppt on polynomials and coordinate geometry software Ppt on switching devices on at&t A ppt on business plan Download ppt on measures of dispersion Ppt on power system engineering Free download ppt on unity in diversity