EXAM 3 (Mods 6 - 8) Flashcards
List the 4 SQL Set Operators
Union, Union All, Intersect, Except
What do the Union and Union All operators do?
Union: Combine rows, with no duplicates, from separate queries.
Union All: Combine rows, allowing duplicates, from separate queries.
What does the Intersect operator do?
Returns all rows common to both queries
What is the result of the Except operator?
Returns rows that appear in the first query but not in the second query (analogous to subtraction).
What are some of the problems that arise when data is stored in one big long table (excel and flat files)?
- Potential for lots of redundant data
- Many updates needed when a single value is changed
- many deletes needed to keep data clean
- Easy for data to become out of sync or outdated
- Structure can be hard to analyze
Benefits of normalizing data into RDMS
Save disc space (not really a concern…CPU-Disc trade off)
Increased efficiency when managing data
Can use SQL -> Remove, insert, update, and delete anomalies
Increase data consistency
Explain the process of normalization
A process applied to the entities of an ER-Diagram to ensure they do not contain hidden repetitive entities that can lead to redundant data. If hidden entities are found, new tables must be made and their relationships defined.
What is the first normal form (1NF)?
Data should be atomic
- Each table cell should contain a single value.
- Each record needs to be unique.
A table with the following attribute value structure for its address column is an example of breaking which normal form?
- 61 William Nock cove, Winnipeg, MB, Canada R2M5S2
1NF
Describe the second normal form (2NF)
Remove functional dependencies on parts of a composite key.
If the value of an attribute changes only with the one part of a key changes and not the combination of the parts you have a 2NF inconsistency and you need to split the entities into separate table
*Only applies if you have a composite key. If table(s) primary key is based on a single attribute then 2NF does not apply!
What is the third normal form (3NF)?
Removes functional dependencies on non-key attributes.
- If value of an attribute is changing based on values of another non-key attribute data is not in 3NF and must split the table to resolve the hidden entity.
Special case of 3NF
Every column is a candidate key. Examples: periodic cable, almost every 2 column table
Four additional considerations for cleaning up ERDs
One-to-One
Chasm
Fan-trap
Redundant
Where to one-to-one relationships make sense/are appropriate?
Subtypes
When does a chasm occur?
When the participation in the relationship is not mandatory…results in no rows coming back when you query.
What are fan-traps?
Occur when you have one-many-many-one. Can cause too many unrelated rows to be returned. Take relationships ambiguous. Better to do many-one then one to many.
How to identify redundant relationships in ERD
- look for a loop in your ERD
- Each pathway needs to describe a different relationship, if they do then loop is valid and may have to stay.