Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Database Design

• Focuses on the design of the database structure that


will be used to store and manage end-user data
• Well-designed database
– Facilitates data management
– Generates accurate and valuable information
• Poorly designed database causes difficult-to-trace
errors
Data Modeling and Data Models
• Data modeling: Iterative and progressive process of
creating a specific data model for a determined
problem domain
• Data models: Simple representations of
complex real-world data structures
– Useful for supporting a specific problem domain
• Model - Abstraction of a real-world object or
event
Importance of Data Models

Are a communication tool

Give an overall view of the database

Organize data for various users

Are an abstraction for the creation of good database


Data Model Basic Building Blocks
• Entity: Unique and distinct object used to
collect and store data
– Attribute: Characteristic of an entity
• Relationship: Describes an association among
entities
– One-to-many (1:M)
– Many-to-many (M:N or M:M)
– One-to-one (1:1)
• Constraint: Set of rules to ensure data
integrity
Entities
• Entities represent logical groupings of data and are the central
concept that defines how data will be stored in the database.

• WHO Person, Employee, Vendor, Customer,


Department, Organisation

• WHAT Product, Service, Raw Material, Training, Course,


Flight

• WHEN Time, Day, Date, Calendar, Reporting Period, Fiscal


Period

• WHERE Geographic location, Storage Depot, Airport

• WHY Order, Complaint, Inquiry, Transaction


Attributes
These are specific pieces of information that describe each
entity.

(entity)
Employee

(Attributes)
• Employee Identifier
• Employee Last Name
• Employee First Name
• Employee Hire Date
• Employee email
Relationships

• Graphical representation of how an entity’s data is related


to another entity.
• One to one relationship
• One to many relationship
• Many to many relationship
One to One relationship
• In a One to One relationship between two tables, a row in one
table can only relate to one row in the table on the other side
of their relationship and vice versa.

Student Student_ID

Person Social_Insurance_number

Phone IMEI
One to many relationship
• In a one-to-many relationship, one record in a table can be
associated with one or more records in another table.

Customer Orders

Patient Hospital_visits

Customer Orders
Many to many relationship
• A many-to-many relationship occurs when multiple records in
a table are associated with multiple records in another table.

Books Authors

Books Authors

Book_Author
Constraints
• Primary Key
• Foreign Key
• Unique Key
• Check
• Not Null
Primary Key
• The PRIMARY KEY constraint uniquely identifies each row in a
table. CUSTOMER
Customer_ID (PK)
First_Name
Last_Name
Gender
Email_id

Customer_ID (PK) First_Name Last_Name Gender Email_id


1 Mary Gold F mary.gold@xyz.ca
2 Jane Smith F Jane.Smith@xyz.ca
3 Susy Summers F Susy.Summers@xyz.ca
4 Jean Grey F jean .grey@xyz.ca
5 Tom Brown M tom.brown@xyz.ca
6 Sam Chang M sam. chang@xyz.ca
7 Maria Cruz F maria.cruz@xyz.ca
Foreign Key
• A FOREIGN KEY is a key used to link two tables together. A primary
key from one table is used to join to another table forming a parent
child relationship.
CUSTOMER ORDERS
Customer_ID (PK) Order_ID (PK)
First_Name Customer_ID (FK)
Last_Name Order_Desc
Gender Order_Qty
Email_id Unit_Price
Order_ID (PK) Customer_ID (FK) Order_Description Order_Qty Unit_Price
1 1 Apparel 4 50.26
2 2 Power Tools 3 45.12
3 2 Books 3 45.5805
4 4 Electronics 550 16.086
5 4 Furniture 3 57.0255
6 5 Office Supplies 100 37.086
7 6 Hardwood 5 26.5965
8 3 Toys 550 27.0585
Unique Key
• You can use UNIQUE constraint to make sure that no duplicate
values are entered in specific columns that do not participate
in a primary key.

CUSTOMER
Customer_ID (PK)
First_Name
Last_Name
Gender
Email_id (UK)
CHECK Constraint
• A check constraint allows you to specify a condition on each
row in a table for a particular column.

ORDERS
Order_ID (PK)
Customer_ID (FK)
Order_Desc
Order_Qty
Unit_Price (CK unit_price >0)
Not Null Constraint
• The NOT NULL constraint enforces a column to NOT accept
NULL values.

CUSTOMER
Customer_ID (PK)
First_Name (NN)
Last_Name (NN)
Gender
Email_id
Business Rules
Brief, precise, and unambiguous description of a
policy, procedure, or principle

Enable defining the basic building blocks

Describe main and distinguishing characteristics


of the data
Sources of Business Rules

Company Department
Policy makers
managers managers

Direct
Written
interviews with
documentation
end users
Reasons for Identifying and
Documenting Business Rules
• Help standardize company’s view of data
• Communications tool between users and
designers
• Allow designer to:
– Understand the nature, role, scope of data, and
business processes
– Develop appropriate relationship participation rules
and constraints
– Create an accurate data model
Translating Business Rules into
Data Model Components
• Nouns translate into entities
• Verbs translate into relationships among entities
• Relationships are bidirectional
• Questions to identify the relationship type
– How many instances of B are related to one instance
of A?
– How many instances of A are related to one instance
of B?
Naming Conventions
• Entity names - Required to:
– Be descriptive of the objects in the business
environment
– Use terminology that is familiar to the users
• Attribute name - Required to be descriptive
of the data represented by the attribute
• Proper naming:
– Facilitates communication between parties
– Promotes self-documentation

You might also like