150 likes | 271 Views
- Questions - “Null values” - Bonus Exercise X Picture on board Eliminate the word ‘potential’ from your database design vocabulary A PC discussion and 1 – 1 relationships Agreements: Picture on board. Relational Database
E N D
- Questions - “Null values” - Bonus Exercise X Picture on board • Eliminate the word ‘potential’ from your database design vocabulary A PC discussion and 1 – 1 relationships Agreements: Picture on board
Relational Database A database that consists of tables and relationships that adhere to a set of rules and provides • data integrity at the field, record, table, relationship and business levels How do we do that? Each one? Record – primary key major tool (why) Field – data type, helper table, …
Relational Database A database that consists of tables and relationships that adhere to a set of rules and provides Data consistency and accuracy How do we do that? Domain restrictions, helper tables, reports, …
Putting database tables into 1st Normal Form, 2nd Normal Form and 3rd Normal Form A database table is in 1st Normal Form if a) Has a primary key b) All fields atomic c) has no repeating fields.
Second Normal Form A table is in 2nd Normal Form if a) It is in 1st Normal Form b) It has no Partial Dependenciesa ‘partial dependency’ is a non-key field in a table that depends on only part of the primary key.
Third Normal Form A table is in 3rd Normal Form if a) It is in 2nd Normal Form b) It contains no Transitive Dependencies Consider an Employee table with empID, fname, lname, spouseSSN, spousefName, spousePhone • Example records • 152 Joe Smith 123456789 Kim 512-332-3313 • 251 Jill Jones • 414 Sarah Kerns 512314123 Tom 212-412-1424
In this table, fname depends on empID, lname depends on empID, spouseSSN depends on empID, spousefName depends on spouseSSN and spousePhone depends on spouseSSN. The spousefname -> spouseSSN -> seuID dependency is a 'transitive dependency'.
To eliminate a transitive dependency, create a new 'Spouse' table consisting of spouseSSN, spousefName and spousePhone. LEAVE the spouseSSN in the Employee table. spouseSSN in the Employee table is a foreign key. Since we are in Texas instead of Utah, this is a 1-1 relationship
Types of relationships between tables 1-1 1-Many Many-Many In a relational DBMS, M-M relationships are resolved into 2 1-M relationships by means of a bridge table/association table/other names by different authors. We’ll call them bridge tables.
1. What is the path to your ‘home’ directory on cn01.cs.stedwards.edu: /seu/cs/home/user/e/tturner2 What is the path to your ‘home’ directory on your vm? 2. If you have a crows foot on a PK – TRC 3. Einstein says “…..” You say “….” Explain in your own words. 4. Make sample records. Make sample records
cn01.cs.stedwards.edu db01.cs.stedwards.edu mysql emacs mysql -h …. mysql …. vm133048.cs.stedwards.edu mysql emacs
A method to resolve M:M relationships Create a new table consisting minimally of the primary keys from each of the participating tables. Normalize the bridge table, with the primary key containing at least each of the keys from the other tables. This table becomes a child table to each of the other tables. The other tables become parents. The respective foreign keys are the primary keys of the parents.
Example of M:MStudentClass seuID dept fname number … Title … One student – many classesone class – many students Create table Enrol seuID dept number grade … as needed
Another example - Entity-Relationship Diagram (ERD) Student seuID (PK) (FK) dept (PK) (FK) number (PK) (FK) semestersection Grade … Class Enrol Some sample records: 111 cosc 3337 SP13 01 cosc 3337 DBMS 111 Jill Student 222 cosc 3337 SP13 01 culf 3331 Amer. D 222 Joe Student 111 culf 3331 SP13 03 How about 111 chem 1301 SP13 02 seuID (PK) fname lname … dept(PK) number (PK) Title …
Integrity Notes from http://www.databasedev.co.uk/database_normalization_process.html • There are 4 types of data integrity: • Entity Integrity ensures that each row (record) is a unique instance in a particular table by enforcing the integrity of the primary key or the identifier column(s) of a table (e.g. ID, Reference Code, etc). • Domain Integrity ensures validity of entries (data input) for a column through the data type, the data format and the range of possible values (e.g. date, time, age, etc.). • Referential Integrity preserves the defined relationships between tables when records are added, modified or deleted by ensuring that the key values are consistent across tables; such consistency requires that there are no references to non-existent values and if a key value changes, all references to it change consistently through database, otherwise a key value cannot be changed. • User-Defined Integrityenables specific (required) business rule(s) to be defined and established in order to provide correct and consistent control of an application's data access (e.g. who can have permissions to modify data, how generated reports should look like, which data can be modified, etc.)