Section 2 Transforming From Conceptual Model To Physical Model
Section 2 Transforming From Conceptual Model To Physical Model
LESSON 1
Objectives
This lesson covers the following objectives:
• Define a primary key
• Define a foreign key
• Define a column-integrity rule
Identify row, column, primary key, unique key, and foreign key elements given a diagram of a table
containing these elements
• Identify violations of data-integrity rules
Purpose
The conceptual data model will be transformed into a relational database design. This means that
our entities, attributes, relationships, and unique identifiers will be translated into objects in a
relational database.
Compare this to a clothing designer who is taking his design from paper and implementing it with
fabric. The designer needs to understand how to sew the designs just like you will need to
understand the structure of relational database objects.
You can see the result of this statement on the next slide.
SQL Query Illustrated
.
.
Summary of Data-Integrity Rules
Data-integrity rules (also known as constraints) define the relationally correct state for a database.
Data-integrity rules ensure that users can perform only those operations that leave the database in a
correct, consistent state.
Terminology
Key terms used in this lesson included:
• Candidate key
• Column
• Foreign key
• Primary key
• Relational database
• Row
• Unique key
Summary
In this lesson, you should have learned how to:
• Define a primary key
• Define a foreign key
• Define a column-integrity rule
Identify row, column, primary key, unique key, and foreign key elements given a diagram of a table
containing these elements
• Identify violations of data-integrity rules
SECTION 2 LESSON 2
Objectives
This lesson covers the following objectives:
• Distinguish between a conceptual model and a physical model
• Apply terminology mapping between the two models
Understand and apply the Oracle naming conventions for tables and columns used in physical
models
• Transform an entity into a table diagram
Purpose
When you design a house, you eventually would like to see the house built. Even if you don’t do the
actual construction, you will need to understand the terms used by the builders in order to help
them take your conceptual design and make it a physical reality.
The initial database design can be used for further discussion between designers, database
administrators, and application developers.
Tables have columns and rows. In the example, each row describes an occurrence of an employee.
Each column is used to store a specific type of value, such as employee number, last name, and first
name.
The employee_id column is a primary key. Every employee has a unique identification number in this
table. The value in the primary key column distinguishes each individual row.
The payroll_id is a unique key. This means that the system does not allow two rows with the same
payroll_id.
The foreign key column refers to a row in another table. In this example, the department_id refers to
a row in the DEPARTMENTS table.
We know that Dana Smith works in department 10. If we wanted to know more about Dana Smith’s
department, we would look for the row in the DEPARTMENTS table that has department_id = 10.
Terminology Mapping
Changing from analysis (conceptual model) to implementation (physical model) also means changing
terminology:
• An entity becomes a table.
• An instance becomes a row.
• An attribute becomes a column.
• A primary unique identifier becomes a primary key.
• A secondary unique identifier becomes a unique key.
• A relationship is transformed into a foreign-key column and a foreign key constraint.
Table Diagram Notations
The first row of the table diagram contains the table name and the short name. The Key Type
column should contain values of “pk” for the primary key, “uk” for the unique key, and “fk” for the
foreign-key column. It will be blank if the column is not a part of any key.
The Optionality column must contain “*” if the column is mandatory and “o” if it is optional. This is
similar to the entity diagram. The third column is for the column name.
For entity names of one word but more than one syllable, take the:
• First character of the first syllable
• First character of the second syllable
• Last character of the last syllable
Example: EMPLOYEE gets a short name of EPE and CLIENT gets a short name of CET
For entity names of one syllable but more than one character:
• First character
• Second character
• Last character
Example: FLIGHT gets a short name of FLT
Table names must be unique within one user account in the Oracle database.
Column names must be unique within a table.
Some words have a special meaning in the Oracle database and in the SQL programming language.
These are called “reserved” words. It is best to avoid using these as names for your tables and
columns.
Terminology
Key terms used in this lesson included:
• Map
• Reserved word
• Transform
Summary
In this lesson, you should have learned how to:
• Distinguish between a conceptual model and a physical model
• Apply terminology mapping between the two models
Understand and apply the Oracle naming conventions for tables and columns used in physical
models
• Transform an entity into a table diagram
SECTION 2 LESSON 3
Relationship Mapping
Objectives
This lesson covers the following objectives:
• Apply the rule of relationship mapping to correctly transform 1:M and barred relationships
• Apply the rule of relationship mapping to correctly transform M:M relationships
• Transform 1:1 relationships
• Apply the rule of relationship mapping to correctly transform relationships in an arc
Purpose
Suppose that you are building a house for someone. You have all of the materials – wood, paint,
doors, windows, nails, screws, etc. – and the skills, but you do not have a design.
As you start, you don’t know how many rooms should be included, where the windows should be
placed, how the doors should be oriented, or what color each room should be painted.
You could build a house in such a manner and make these decisions as you go, but if you do not start
with a blueprint of the structural design, the final product may not be the house that the customer
has in mind.
Relationships are mapped between primary keys and foreign keys to allow one table to reference
another. If we don’t map relationships, we just have a lot of standalone tables containing
information that does not connect to anything else in the database.
We use the short name of the table to name the foreignkey column. In the example on the next
page, the foreignkey column in the EMPLOYEES table is dpt_id for the relationship with
DEPARTMENT, and epe_id for the recursive relationship with itself.
The foreign-key column may be either mandatory or optional, depending on the needs of the
business. In the example, dpt_id is mandatory and epe_id is optional.
Rules for Relationships Illustrated
In the following example, the physical model cannot enforce that a BAND must be composed of at
least one MUSICIAN. The optionality at the one end will have to be implemented through additional
programming.
Enforcing Optionality
A barred relationship is mapped to a foreign-key column on the many side, just like any other 1:M
relationship. In this case, the foreign-key column plays a double role because it is also part of the
primary key.
In the example, bak_number is a foreign-key column in ACCOUNTS that refers to the primary key of
BANKS. It is also part of the primary key of ACCOUNTS.
When this is mapped to a physical model, the result can be a very long foreign-key column name
because it uses the short names of the originating tables as a prefix. The suggested convention is to
never use more than two table prefixes. In the following example, the foreign-key column in ROOMS
that comes all the way from BUILDINGS is named sue_bdg_id, instead of sue_flr_bdg_id.
Cascade Barred Relationship Illustrated
Optional One-to-One
If the relationship is optional on both sides, you can choose which table gets the foreign key. There
are no absolute rules, but here are some guidelines:
• Implement the foreign key in the table with fewer rows to save space.
• Implement the foreign key where it makes more sense for the business.
In the example, a car-rental agency would be more concerned about cars than spaces, so it makes
sense to put the foreign key in CARS. However, in a parking-lot business, the main object is the
parking space. Therefore, it would make sense to put the foreign key in SPACES.
Enforcing One-to-Many
If the relationship is mandatory at both ends, you have the same limitation in the database as a 1:M
relationship that is mandatory at the one end. Therefore, you would need to write additional code to
enforce it.
Mapping Arcs
The entity that has the arc will map to a table that contains foreign keys from the tables on the
“one” end of the relationships.
Note that even if the relationships in the arc are mandatory on the many side, the resulting foreign
keys have to be optional (because one of them will always be blank).
Since the arc represents exclusive relationships, additional code is needed to enforce that only one
of the foreign keys has a value for every row in the table. A check constraint stored in the database
can easily do this. In the example, the code for the check constraint would look like this:
CHECK (pse_id is not null AND phe_id is null) OR (pse_id is null AND phe_id is not null)
If the relationships were fully optional, you would add: OR (pse_id is null AND phe_id is null)
The code verifies that if a value exists for the public space id (pse_id), then the column for private
home id (phe_id) must be empty. Conversely, if the public space id is NULL, then a value must exist
for the private home id. In a fully optional relationship, additional code allows both the public space
id and the private home id to be null (the event is not held at any venue).
Terminology
Key terms used in this lesson included:
• Cascade barred relationship
• Intersection entity
• Nontransferable relationship
Summary
In this lesson, you should have learned how to:
• Apply the rule of relationship mapping to correctly transform 1:M and barred relationships
• Apply the rule of relationship mapping to correctly transform M:M relationships
• Transform 1:1 relationships
• Apply the rule of relationship mapping to correctly transform relationships in an arc
SECTION 2 LESSON 4
Subtype Mapping
Objectives
This lesson covers the following objectives:
State and apply the table, column, identifiers, relationship, and integrity constraint rules for
mapping:
–supertype implementations
–subtype implementations
–supertype and subtype arc implementations
Purpose
A carpenter who is building your dream house may know that you will use different types of light
bulbs all around the house. However, if you do not provide information on where certain types of
light bulbs should be installed, you could end up with an overly bright bedroom and a dimly lit
kitchen!
Mapping supertypes and subtypes makes sure that the right information gets stored with each type.
In the conceptual model, salary is mandatory for full-time employees and hourly rate is mandatory
for part-time employees. When the EMPLOYEE supertype is implemented as a single table in the
physical model, these attributes become optional. A check constraint is needed to enforce the
business rules modeled in the ERD.
In the example, the code for the check constraint would look like this:
CHECK (epe_type = ‘FTE’ and salary is not null and hourly_rate is null and agy_id is null)
OR (epe_type = ‘PTE’ and salary is null and hourly_rate is not null and agy_id is not null)
The code checks that if it is a full-time employee (epe_type = ‘FTE’), then a value must exist in the
salary column and the hourly_rate and agy_id columns must be empty. Conversely, if it is a part-time
employee (epe_type = ‘PTE’), then a value must exist in hourly_rate and agy_id, but salary must be
left blank
In the example, a separate table would be created for SHIRTS and SHOES.
Terminology
Key terms used in this lesson included:
• Arc implementations
• Subtype implementations
• Supertype implementations
Summary
In this lesson, you should have learned how to:
State and apply the table, column, identifiers, relationship, and integrity constraint rules for
mapping:
–supertype implementations
–subtype implementations
–supertype and subtype arc implementations