Database Modeling: Relationships Flashcards

1
Q

What are the three kinds of relationships in a RDBMS?

A
  1. One-to-one (not used much)
  2. One-to-many (dwarfts them all)
  3. Many-to-many (used a bit)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is another name for a relationship in a RDBMS?

A

Cardinality

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe the linear steps for modeling a DB?

A
  1. Sketch your entities (which will become your tables)
  2. Define the data (attributes) for those entities. These become the columns in the tables.
  3. Determine which columns will be the primary keys and if they need to be generated (surrogate keys).
  4. Define your relationships.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a foreign key?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s a good way to make sure you have a true one-to-one cardinality?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can a relational DB directly represent many-to-many relationships? If not, how are many-to-many relationships handled?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is referential integrity?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly