What's a Database A Database Primer
Let’s discuss databases n Why they are hard n Why we need them
Advantages of Database Processing n More information from the same amount of data n Share Data n Balance Conflicting Requirements n Control Redundancy n Facilitate Consistency n Improve Integrity n Expanding Security n Increasing Productivity n Provide Data Independence
More information from the same amount of data n Data + Processing = Information
Share Data n Islands of data are difficult to share n Conflicts with file structures, naming conventions
Balance Conflicting Requirements n Different parts of the business have different uses for the data
Control Redundancy n Single authoritative source
Facilitate Consistency n One source – no conflicting data
Improve Integrity n Refer to single authoritative source n Ensure that single source is correct
Expanding Security n Put all your eggs in one basket n Watch the basket
Increasing Productivity n Only one place to store n Only one place to look n Prepare data once
Data Independence n Changes in the physical structure do not affect the logical structure = scalability
Topics n Manual database example
Manual database example
Structure n Fields, Records, Files n Columns, Rows, Tables n Attribute, Tuple, Relations n Rules: Types of data you can enter
More Complex Model n What if….
A Database is… n Tables n Relationships n Queries n Forms n Reports n Programs
A Student Record
A Few Students
Table View
A Few Students Kelly moves
Redundant Data leads to Inconsistent Data Bud moved too but now the addresses don’t match! His record still has the old address.
A Solution?
Move the data that is common to several records to a new table
A Solution!
A Solution
Relationships Primary Keys Foreign Key
Even More Relationships
Lots of Tables
Normalize? 1 st Normal Form At each row-column intersection, there must be one, and only one, value. F For example, a database would violate the rule for the first normal form if it stores, in a single row- column intersection, all of the scores for a bowler
2 nd Normal Form n Every non-key column must depend upon the entire primary key. n No non-key column is dependent on only a portion of the primary key u If the primary key is composite-made up of more than one component - no non-key column can be a fact about a subset of the primary key. u e.g. compound key firstname+lastname+province code would violate this rule, if another column was functionally dependent on the province code (John+Smith+BC) if “British Columbia” is functionally dependent on the code BC Only an issue if you have compound primary keys e.g. name + product code
3 rd Normal Form n No non-key column can depend on another non-key field u Each column must be a fact about the entity identified by the primary key u All determinants are candidate keys u e.g. in a table about people that contains a column with province codes, and another column with the full name of the province, the province code is a determinant of the full name, but is not a candidate key for the table of people Def n : Determinant A column that determines another column is a determinant
4 th Normal Form n There must not be any independent one-to-many relationships between primary key columns and non-key columns i.e. There are no multivalued dependencies IDAnswer1Answer2Answer3 223ABC 224BCA
5th Normal Form n Tables are broken into the smallest possible pieces in order to eliminate all redundancy within a table. n In extreme cases, tables in fifth normal form may consist of a primary key and a single non-key column. n High integrity n Slow performance n Redundancy due to extensive use of foreign keys
Summary – Normal Forms Normal Form Meaning/ConditionsNotes FirstNo repeating groups exist Second1NF + no nonkey column is dependent on a portion of the primary key If primary key is a single column then automatically 2NF Third2NF + the only determinants are candidate keys Boyce-Codd Normal Form Fourth3NF + no multivalued dependencies
A Historical Perspective Physical collections Flat Files Lists Indexes and pointers
Other Perspectives Hierarchical Structures Folders and Files Inverted Tree Organization Charts Single parent – many child relationships Network Multi – parent – many child relationships
What do you normalize? n Office u Supplies u Inventory n Office u Kitchen u Bathroom
Relational n Fields, Records, Files n Columns, Rows, Tables n Attribute, Tuple, Relations n Structure and Relationships