Database Modeling: Relationships Flashcards
What are the three kinds of relationships in a RDBMS?
- One-to-one (not used much)
- One-to-many (dwarfts them all)
- Many-to-many (used a bit)
What is another name for a relationship in a RDBMS?
Cardinality
Describe the linear steps for modeling a DB?
- Sketch your entities (which will become your tables)
- Define the data (attributes) for those entities. These become the columns in the tables.
- Determine which columns will be the primary keys and if they need to be generated (surrogate keys).
- Define your relationships.
What is a foreign key?
A foreign key is a key to a row in a different table. It is a primary key used in a table other than its own.
What’s a good way to make sure you have a true one-to-one cardinality?
Look at the relationship from both ways. One-to-one relationships are rare and are usually one-to-many or many-to one.
Usually the two tables with a one-to-one relationship can be merged into the same table, negating the need for cardinality.
Can a relational DB directly represent many-to-many relationships? If not, how are many-to-many relationships handled?
No. Many-to-many relationships require a linking (junction, joining, cross-reference, etc) table. This joining table only has two columns, one for each foreign key from each of the tables it joins.
Usually linking tables do not have a primary key.
What is referential integrity?
Enforcing the rules of a relationship; maintain the validity of data between tables. For example, if an Order table requires a customer ID, referential integrity will not let you create an order without a customer. Same thing with delete: the DBMS can be configured to prevent deleting any customers who are linked to orders.