Database Design Cheatsheet
Database Design Cheatsheet
Identify the domain entities. For Define the attributes for each entity. 1NF One-to-one Filter out redundancies.
example, for an online store:
● Customers For example: Atomic values for each attribute. No has
● Products ● Customer’s attributes can be: values like: “‘phoneX, tabletY, laptopZ”
● Reviews email, first_name, last_name, etc. for a ‘favorite_product’ attribute in
● Product attributes: id, name, One Capital
Customers table. One Country
If there is data that doesn’t fit in this description, price City
entities categories, probably it’s an Non Repeating groups: No columns ● Foreign Key can be on each side.
Decide what primary keys to use: (attributes) like: favorite_product1, ● It can be forced using an UNIQUE
attribute.
email for a customer (or assign an favorite_product2, favorite_product3 in constraint.
unique number id), id for a product the Customers table
(which could be the barcode number, One-to-Many / Many-to-one Examine the Database design and if
or an unique auto generated number) Records (rows) are unique. A redundancies are found, remove them.
customer with id = 111, appears only
once in the Customers Table owns
Customers
Customers 2NF
id email first_name last_name
One (Rich) Many Review with Client
Non-key (non prime) attributes are
Person Houses
depended on the whole composite
Products key. Eg: Column ‘price’ in Reviews table
● Foreign Key is on the Houses side
Products breaks 2NF. It is depended only on the
referencing a person’s id
id name description price product_id.
(Houses.person_id)
All tables that have only one attribute
Reviews as primary key are in 2NF by default. Many-to-Many
Reviews customer product rating comme
_id _id nts
3NF
[Every] non-key [attribute] must be Review the specifications with your
depended on the key, the whole key, A customer A product is client to ensure that the database
and nothing but the key. reviews many reviewed by many model supports the data requir
Adding ‘brand’ and ‘brand_description’ products customers ements.
in Products table breaks 3NF.
‘brand_description’ is depended on ● Use intermediary table that holds
‘brand’, which is not a key. the foreign keys.
1. Define Domain 2. Define Attributes & 3. Apply Normalization 5. Build the tables 6. Polish the
Entities Primary Keys 1FN, 2FN, 3FN relationships design