Logical Database Design and The Relational Model: Peter Kaaya
Logical Database Design and The Relational Model: Peter Kaaya
CUSTOMER
Cust_id
Cust_name
Address
phone
• To convert it into a corresponding relation, write the entity name
instead of R write CUSTOMER
• i.e CUSTOMER (cust_id, cust_name, address,phone); cust_id (PK)
A relation
• Is a named, two dimensional table of data
• A table consists of rows and columns
• Row (Record) and column (attribute/field)
Cont…
TABLE RELATION
COLUMN ATTRIBUTE/DOMAIN
ROW TUPLE/RECORD
ORDER
Order_id Order_date Cust_id
ORDER_LINE
Order_id Prod_id quantity
PRODUCT
Prod_id Prod_desc Prod_finish Prod_price Prod_line
INTEGRITY CONSTRAINTS
• Domain constraint
• Allowed values for an attribute
• E.g. Domain for AGE can be only numbers
• i.e domain_numbers (0-999)
• Domain:- 3 digits
• Entity Integrity
• Means that NO primary key should remain EMPTY/NULL without any input
ie. The primary key field must have data
• NB :Zero is an input and make sure that no value has been entered
• PK must not be null because it is the one that uniquely identifies that row
ACTION ASSERTION
• Refers to a statement of a constraint / control on the actions of the
organization
• Business rule constraint:: MUST/MAY
• Concerned mainly on business rules by looking if its optional
/mandatory. If its optional its constraint may be MAY
REFERNTIAL INTEGRITY
• Mainly concerned about foreign keys.
• Its rule states that : any foreign key value must match a primary key
value in a relation of one side i.e. foreign key must be migrating to
the many side
• E.g. DELETE rule
• Restricts. Don’t allow delete of PARENT side if related row exists
For example:
CUSTOMER
Cust_id Cust_name Cust_address Gender city
ORDER
Order_id Order_date Cust_id
ORDER_LINE
Order_id Prod_id quantity
PRODUCT
Prod_id Prod_desc Prod_finish Prod_price Prod_line
DELETE Rules:
• Don’t allow delete of parents side if related row exists
CASCADE:
• Automatically delete dependent side rows that correspond with the
parent side row to be deleted
SET TO NULL
• Set the foreign key in the dependent side to NULL if deleted from
parent side table .i.e. NOT allowed for weak tables
MAPPING REGULAR ENTITIES TO RELATIONS
1. SIMPLE ATTRIBUTES
• ER attributes map directly onto the relation e.g. name, age, sex, gender etc
E.g. convert a simple entity into a relation CUSTOMER
Cust_id
Cust_name
Address
phone
Customer relation
CUSTOMER
Cust_id, cust_name, address, phone
2. COMPOSITE ATTRIBUTES
Use only their simple , component attributes
CUSTOMER
e.g. P_O_box, city, House_no, postal_code etc
Cust_id
i.e an attribute containing some more attributes within it
Cust_name
e.g. name:- middle_name, sir_name, tour_name Address
use only their simple component attributes (street,city,state)
phone
Relation with address detailed
CUSTOMER
Cust_id Cust_name street City state phone
CUSTOMER_SKILLS
Cust_id skill
STRONG ENTITIES
• Exist independently of other types of entities
• Has its own unique identifier
• Identifier is underlined by a single line
WEAK ENTITIES
• Dependent on a strong entity (identifying owner) cant exist on its own
• Doesn’t have a unique identifier (only a particular identifier)
• Partial identifier underlined with a double line
• Entity box has double line
• Primary key can depend on its own without relationship with other
dependent entity/ies
EMPLOYEE DEPARTMENT
Emp_name dept_name
(f_name,m_name,l_na
Emp_id me)
dob
EMPLOYEE DEPARTMENT
ORDER