Week 4 Flashcards
Normalization
- goal is to avoid unneccessary data duplication
- decomposing relations to well organized relations
What does not normalized data look like?
What does normalized data look like?
- LOTS of duplication (Think tons of repeat supplier names for every product)
-make to 3 smaller tables and have no repeats! keep relationships to other tables through foreign keys
What is a well-structured relation
- no data redundancy, allowing users to insert/delete/update rows w/o inconsistencies
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
- first normal form: no multi value attributes (a divided cell!) so all columns should only have one value (Remove partial dependencies)
- second normal form: within a single table, no 2 entities should have many to many relatinshiom (remove transitive dependencies)
- Third normal form: remove any other one to many relationships
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
- unqniue name
- every att must be singular! no mv
- every row must be unique
- columns must be uniqe
- order of rows and columsn not relevant
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