Normalization
What does not normalized data look like?
What does normalized data look like?
-make to 3 smaller tables and have no repeats! keep relationships to other tables through foreign keys
What is a well-structured relation
GOAL: AVOID ANOMALIES
What are the types of anomalies that can arise
Insertion: adding new rows forces user to create duplicated data
Deletion: deleting rows may cause a loss of data that may be needed for future rows
Modification: changing data forces changes to other rows because of duplication
Rule of thumb about well structured relations
TABLE SHOULD NOT HAVE >1 ENTITY TYPE
(HAVE a lot of foreign keys but one entity type only)
Steps in normalization
how do you know something is in a relationship database?
PKs and FKs
Can be searched with SQL queries
what is a relation?
two dimensional table of data! not a relationship!!
requirements for a relation
can keys be simle or composite
yes both!h
what is the point of indexes?
indexing!! keys do this!
Constraints: 3 types
domain- what are the allowable values for an attribute
entity integrity- PK must be not null and unique
referential integrity- MOST IMPORTANT! consistency!!! if you use FK it must exist
3 approaches to ensure referential integrity
restrict: restricting from deleting by cnnecting to FK
cascade: when you delete a parent row litl the relevant dependant cell will also be deleted
set to null: sets dependant cells to null
how to create referential integrity constriants??????? in sql
just link the FK’s!!!!
how to map entities to relaitons/tables
simple attribute (no mv!): each becames its own column
composite attributes: use only their simple, ocmponent attributes; each mv becomes onw column
How to handle foreign keys/primary key?
how to handle weak entities in creating an ERD in SQL?
2 WAYS FOR WEAK ENTITIES TO HAVE PK:
a) partial identifier + parent identifier
b) surrogate identifier
how to handle a ternary relationship?
Create 3+ FKS in the singular entity that has many pointing to it!
WHERE DO YOU ADD A FOREIGN KEY?
ON THE MANY SIDE!!! OF THE CARIDNATILITY
How to handle composite attributes?
break into separate rows in the entity table
why do we call it a relation
mathematics!
Relational schema:
How to read it?
How to handle composite attributes in entity relationship diagrams?
Company address (city, psotal code)
you make each composite attribute its own attribute (each has its own “column” which become a row in the entity)
How to handle multivalue attributes
{Skills} in entity relationship diagram?