170 likes | 331 Vues
Relational Model. Stores data as tables Each column contains values about the same attribute Each column has a distinct name Each row contains values for a given entity Each row is distinct Order of columns (and rows) is immaterial Cells are single valued. Terminology. Relationships.
E N D
Relational Model • Stores data as tables • Each column contains values about the same attribute • Each column has a distinct name • Each row contains values for a given entity • Each row is distinct • Order of columns (and rows) is immaterial • Cells are single valued
Relationships • An association between entities • Unary (recursive) • Binary • One to Many or Many to Many • Ternary • Quaternary
Binary Relationships • One to one • Each row in a table has at most one matching row in another table • One to many • Many to many • A row in the first table matches many rows in the second and a row in the second matches many rows in the first
Keys • Superkey • an attribute or a set of attributes that uniquely identifies a row within a table • Candidate • unique and irreducible identifier of a row, for all time (minimal superkey) • Primary • chosen candidate key for a table • Alternate
Keys (continued) • Secondary • an attribute used for sorting and retrieval • Composite • a key made of more than one attribute • Foreign • used to designate relationships
Database Design Language (DBDL) • Include all attributes (separated by commas) within parentheses with the name of the table outside the parentheses • Underline the primary keys • List any alternate, secondary and foreign keys identified by the letters AK, SK and FK respectively • Foreign keys are followed by an arrow pointing to the relation identified by the foreign key
Representing Relationships • One to one • create a foreign key • One to many • place primary key of parent in child table • Many to many • Break into two one to many relationships
Student # Student # Course # Name Course # Name Major Grade Instructor Student Grade Course
Entity Relationship Design • Determine potential entities (rectangles) • Identify relationships (diamonds) between entities • Identify the attributes (ovals) of the entities • (and the attributes for any M:N relationships) • Identify the primary keys
Integrity rules • Entity integrity • No column that is part of the primary key may accept null values. • Referential integrity • If table A contains a foreign key that matches the primary key of table B, then values of this foreign key either must match the value of the primary key for the same row in table B or must be null.
Integrity Services • Domain integrity • ensures that values assigned to a field are in that field’s domain • Relation integrity • ensures that related fields are in the same level of update
Referential Constraints • Cascading Updates Option If the value of the primary key in the primary (referenced) table is changed, then all values of the appropriate foreign key in the related (referencing) table are automatically changed to the new value • Cascading Deletes Option If you delete a record in the primary (referenced) table, then all records in the related (referencing) table that have matching foreign key values will also be deleted
Main/Subforms • First define the 1:N relationship between the tables • Create a main form for data from the primary table • Create a subform for the data from the related table (Similarly you can display records from the related table as a sub-datasheet in the primary table’s datasheet)
Assignment 2 • MS Access 2000 • Page AC 4.33 • #6-9 (first set up a relationship between the tables)