Download presentation
Presentation is loading. Please wait.
Published byRalph Willis Modified over 9 years ago
1
Bordoloi CMIS 450: Database Design Dr. Bijoy Bordoloi Transforming E/R Diagrams to Relations
2
Bordoloi Represent Entities Each entity-type in E/R Diagram becomes a Relation (Table)Each entity-type in E/R Diagram becomes a Relation (Table) The identifier of the entity-type becomes the PK of the corresponding relation (provided the PK meets all the necessary criteria discussed earlier)The identifier of the entity-type becomes the PK of the corresponding relation (provided the PK meets all the necessary criteria discussed earlier) Each non-key attribute of the entity-type becomes a non-key attribute of the relationEach non-key attribute of the entity-type becomes a non-key attribute of the relation
3
Bordoloi Represent Entities QuestionQuestion –What happens if you allow (non-identifying) multi-valued attributes in an entity-type? Can the identifier of an entity-type then also be the PK of the corresponding relation?
4
Bordoloi Attributes Cardinality Describes association between attribute and owner entityDescribes association between attribute and owner entity Single-valued attribute has at most one value for each entity instanceSingle-valued attribute has at most one value for each entity instance Multi-valued attribute has many values for some entity instancesMulti-valued attribute has many values for some entity instances
5
Bordoloi Attributes Cardinality EMPLOYEE EMP-ID SS-NUM SEX EXTENSION**
6
Bordoloi Multi-valued Attributes Either redefine the Primary Key* or make a separate relation with a foreign key taken from the superior entity Either redefine the Primary Key* or make a separate relation with a foreign key taken from the superior entity * Refer to class notes on Relational Model – Primary Key
7
Bordoloi Multi-valued Attributes Multi-valued attributes become new characteristic tablesMulti-valued attributes become new characteristic tables EMPLOYEE EMP# E-NAME DATE TITLE M M N N EMPLOYEEHISTORY EMP#E-NAME EMP# TITLEDATE 1 11 N N N
8
Bordoloi Multi-valued Attributes Characteristic table is necessary because relational model is normalizedCharacteristic table is necessary because relational model is normalized EMP#E-NAMETITLE HISTORY DATEEMP#E-NAME EMPLOYEENOT IN 2NF MA TABLE EMP # DATE TITLE E1 3-15-85 JANITOR E1 3-16-85 TECHNICIAN E1 3-17-85 MANAGER E2 2-23-87 EMPLOYER E2 4-19-88 DOGCATCHER
9
Bordoloi Transforming Relationships Mapping Binary Relationships –One-to-Many – and One-to-One relationships become foreign keys. –Many-to-Many - Create a new relation with the primary keys of the two entities as its primary key
10
Bordoloi Cont’d In N-1 relationship, always place foreign key at ‘N’ sideIn N-1 relationship, always place foreign key at ‘N’ side In 1-1 relationship, usually place foreign key in smaller table (results in fewer null values)In 1-1 relationship, usually place foreign key in smaller table (results in fewer null values)
11
Bordoloi Representing a (1:N) Relationship CUSTOMER ORDER Place s CUSTOMER NO. NAME CITY STATE ZIP ADDRESS DISCOUNT ORDER DATE PROMISED DATE ORDER NO. a) E-R Diagram
12
Bordoloi Representing a (1:N) Relationship b) Relations
13
Bordoloi Mapping a binary 1:1 relationship (a) Binary 1:1 relationship
14
Bordoloi Figure (b) Resulting relations
15
Bordoloi NULL Values in Foreign Keys Whether or not a Foreign Key can have NULL values depends on the minimum cardinality of the concerned relationshipWhether or not a Foreign Key can have NULL values depends on the minimum cardinality of the concerned relationship Minimum cardinality of 0 represented as NULL allowed for foreign key columnsMinimum cardinality of 0 represented as NULL allowed for foreign key columns Minimum cardinality of 1 represented as NULL disallowed for foreign key columnsMinimum cardinality of 1 represented as NULL disallowed for foreign key columns
16
Bordoloi Sub-tables Sub-entity - a subset of another entity, called the super-entitySub-entity - a subset of another entity, called the super-entity –Has 1-1 relationship to the super-entity (IS-A) –Are existence-dependent on the super-entity EMPLOYEE AGENT CLERK PROGRAMMER
17
Bordoloi Sub-entities become sub-tables in baseline logical design, but may merge with super-table in final design Any kind of table may have sub-table Sub-tables EMPLOYEE PROGRAMMER SYSTEM ASSIGNMENT PERMANENT TEMPORARY
18
Bordoloi Design of sub-table Foreign key identifies super-tableForeign key identifies super-table Primary key-foreign key with no qualifying columnsPrimary key-foreign key with no qualifying columns Foreign key rules reflect existenceForeign key rules reflect existence –Nulls not allowed –Delete cascades –Update cascades EMPLOYEE PROGRAMMER
19
Bordoloi Design of sub-table CREATE TABLEPROGRAMMER (EMP#, LANGUAGE, LEVEL) PRIMARY KEY(EMP#) FOREIGN KEY(EMP# IDENTIFIES EMPLOYEE NULLS NOT ALLOWED DELETE OF EMPLOYEE RESTRICTED UPDATE OF EMPLOYEE CASCADES) Optional class column in super-table improves performance, but is redundant to data in sub-tablesOptional class column in super-table improves performance, but is redundant to data in sub-tables
20
Bordoloi Representing IS-A Relationships PROPERTY MOUNTAIN PROPERTY BEACH PROPERTY CITY STATE ZIP STREET ADDRESS TYPICAL RENT NO. ROOMS STREET ADDRESS CITY STATE ZIP SKIING BLOCKS TO BEACH (a) E-R diagram IS-A
21
Bordoloi Representing IS-A Relationships (b) Relations
22
Bordoloi Associative Tables Associative Tables M-N relationship becomes associative table with two foreign keysM-N relationship becomes associative table with two foreign keys
23
Bordoloi Associative Tables Associative tables also known as association or intersection tableAssociative tables also known as association or intersection table EMPLOYEEPROJECT EMP#E-NAMEP-NAMEP# 1N EMPLOYEEPROJECT EMP#E-NAMEP-NAMEP# ASSIGNMEN T EMP#P# MN N1
24
Bordoloi Transforming Relationships Mapping Unary Relationships What do you do when the relationship is unary? What do you do when the relationship is unary? Rules are the same irrespective of whether the relationship is unary or binary. 1:N and 1:1 relationships be come foreign keys in the same table. M:N relationship becomes a separate (associative table). Rules are the same irrespective of whether the relationship is unary or binary. 1:N and 1:1 relationships be come foreign keys in the same table. M:N relationship becomes a separate (associative table).
25
Bordoloi In-Class Exercise: Transform the following ERD to a relational structure EMPLOYEE DIVISION DEPARTMENT SSN EMP# FNAMELNAMESALARY JOBCODE MARRIED-TO BLDGDIVNAME DEPT# DEPTNAME DIRECT WORK-IN MANAGE BELONG-TO
26
Bordoloi Reverse Engineering Modify the previous ERD to reflect the existence of the following five tables Modify the previous ERD to reflect the existence of the following five tables
27
Bordoloi More Example Tables
28
Bordoloi More Example Tables
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.