21
DATA MODELING AND DATABASE DATA MODELING AND DATABASE DESIGN DESIGN Part 3 Part 3

DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Embed Size (px)

Citation preview

Page 1: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

DATA MODELING AND DATA MODELING AND DATABASE DESIGNDATABASE DESIGN

Part 3Part 3

Page 2: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Objectives

• Translate Logical to Physical design

• Steps for converting (mapping) Resolved ERD to set of Table Instance Charts

• Table Instance Charts symbols.

• Some mapping examples

Page 3: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Database Design -from Logical to Physical

• Map entities and attributes to tables and columns respectively.

• Naming conventions should be consistent.

• Consider primary, unique and foreign keys

and check constraints as well

• Additional requirements– Design the indexes

– Establish view definitions

– Plan the physical storage space

Page 4: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Steps to convert your Resolved ERD to TIC set

• Map ENTITIES to TABLES

• Map ATTRIBUTES to COLUMNS

• Map * to NOT NULL constraints

• Map UIDs to PRIMARY KEY constraints

• Map (#) Secondary UIDs to NOT NULL and UNIQUE Constraints

• Map RELATIONSHIPS to FKs

Page 5: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Table Instance Chart Symbols

• PK - Primary Key

• FK - Foreign Key

• FK1, FK1 - Composite Foreign Keys

• FK1, FK2 - Two foreign keys related to two separate tables

• NN - Not Null

• U - Unique

• U1, U1 - Two columns unique in combination with each other

• U1, U2 - Two unique (and indepenent) columns

Page 6: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Column nameKey typeNulls/UniqueFK tableFKcolumnDatatypeMax lengthValidate

emp_no

PK,FK

EMPLOYEEemp_no

NUM7

position

NN

CHAR25

salary

NN

NUM11,2

Comm

NUM4,2

Creating a TIC: ExampleCreate a Table Instance Chart (TIC) from the Logical Schema (Resolved ERD)

EMPLOYEE_NEW_FORCE TableEMPLOYEE_NEW_FORCE Table

Columns

Keys

Reference

< 10000 < 1

Page 7: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Steps for creating TIC1: Map Entities to Tables

• Create a frame for each TIC– Table name

– Column names

– Key types

– Not Null and Unique references

– Foreign key information

– Column datatype and maximum length

_ Validation (Check)

– Sample data

• Put the table name at the top of the chart.

Page 8: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Step 2: Map the Attributes to Columns

• Map each attribute from the entity to a column name in the table.

• Mandatory columns get a NN constraint

• Add sample data for each column (usually three rows)

• Do not use SQL reserved words for column names.

Page 9: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Step 3: Map the Unique Identifiers to Primary Keys

• Map the UID of the entity as the primary key in the table.

• Do NOT mark it as NN and U

• If there is an alternate UID, label it as NN and U,but choose only one for a PK.

• Add a FK column for each UID that is through a relationship (over UID bar)

Page 10: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Step 4: Map Relationships to Foreign Keys

• For One-to-Many relationships– Take the PK at the One end and create a

column under same or different name in the other table at the Many end.

– Mark it as a FK.

• For mandatory relationships, be sure to label the NN reference.

Page 11: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Step 4: Map Relationships to Foreign Keys --- continued

• For One-to-One relationships, label the U reference.– If the relationship is optional in both

directions, place the FK in the table at either end of the relationship.

– If the relationship is mandatory, place the unique FK in the table at the mandatory end.

• For mandatory relationships, be sure to label the NN reference.

Page 12: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

MAPPING: Example

EMPLOYEE_NEW_FORCE ACTIVITY

EMPLOYEE_ACTIVITY

* per_diem_rate

# emp_no* positiono job_description* salaryo commission

# activity_id* descriptiono start_dateo end_date* internal

requires

for

performs

performedby

Page 13: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Entities to tablesEMPLOYEE_NEW_FORCE ACTIVITY

EMPLOYEE_ACTIVITY

Page 14: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Attributes to ColumnsColumn Name id description start_date end_date internal

KeyType Nulls/Uniques

FK RefTableFK ColumnDatatypeMAX LengthValidation

ACTIVITY

Page 15: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

UID to PK and * to NOT NULL

KeyType Nulls/Uniques

FK RefTableFK ColumnDatatypeMAX LengthValidation

ACTIVITY

PK

NN NN

Column Name id description start_date end_date internal

Page 16: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

If Entity on Many side, then add FK Column

KeyType Nulls/Uniques

FK RefTableFK ColumnDatatypeMAX LengthValidation

ACTIVITY

PK

NN NN

Column Name id description start_date end_date internal

NN

We do NOT have here a FK Column !

Page 17: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Validation (Check) on Columns with Limits

KeyType Nulls/Uniques

FK RefTableFK ColumnDatatypeMAX LengthValidation

ACTIVITY

PK

NN NN

Column Name id description start_date end_date internal

>= sysdate {Y,N}

NN

Page 18: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

LINK - INTERSECTION ENTITIES

EMPLOYEE_ACTIVITY

forfor

Page 19: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

PK and NN

Column Name emp_no activity_id per_diem_rate

KeyType PK PK

Nulls/Uniques NN

FK RefTable

FK refColumn DatatypeMAXLength

EMPLOYEE_ACTIVITY

Page 20: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Foreign KeysColumn Name emp_no activity_id per_diem_rateKeyType PK, FK1 PK, FK2

Nulls/Uniques NN

FK Ref . EMPLOYEE_ ACTIVITY table NEW_FORCE

FK refColumn emp_no activity_id Datatype Number Number NumberMAXLength 6 6 7,2

EMPLOYEE_ACTIVITY

Page 21: DATA MODELING AND DATABASE DESIGN Part 3. Objectives Translate Logical to Physical design Steps for converting (mapping) Resolved ERD to set of Table

Foreign Key Mapping Rules

• Map the Relationship to a foreign key.

• One to One optional in both directions - take the PK from either table and make it a FK in the other table.

• One to One mandatory in one direction, take the PK from the optional end and make it a FK in the entity at the mandatory end.

• One to Many - Take the PK at the one end and make it a FK in the entity at the many end.

• Do not forget to label mandatory relations with NN