File notes/lectures_notes.md changed (mode: 100644) (index 646fd11..2cfccc6) |
... |
... |
DRIVER(State (PK), Licence\_number (PK), Name, Address) |
868 |
868 |
INSURANCE(Policy\_Number (PK), Insured\_Car (FK to CAR.VIN), Insured\_Driver\_State (FK to DRIVER.State), Insured\_Driver\_Num (FK to DRIVER.Licence\_number), Rate) |
INSURANCE(Policy\_Number (PK), Insured\_Car (FK to CAR.VIN), Insured\_Driver\_State (FK to DRIVER.State), Insured\_Driver\_Num (FK to DRIVER.Licence\_number), Rate) |
869 |
869 |
PRICE(Stock\_number (PK), Car\_Vin (FK to CAR.VIN), Price, Margin) |
PRICE(Stock\_number (PK), Car\_Vin (FK to CAR.VIN), Price, Margin) |
870 |
870 |
](fig/rel_mod/car_01) |
](fig/rel_mod/car_01) |
871 |
|
\ |
|
|
871 |
|
\ |
872 |
872 |
|
|
873 |
|
(Yes, we do need the state *and* the licence number to uniquely identify a driver's licence, since [many states use the same licence format](https://ntsi.com/drivers-license-format/). |
|
|
873 |
|
- In CAR, VIN is the primary key, so it must satisfy the entity integrity constraint, and its value can not be `NULL`. Note also that all the values must be different, as the same value cannot occur twice as the primary key of tuples: we don't want to enter the same VIN twice, that would mean we are registering a car that was already registered in our database! |
|
874 |
|
- In DRIVER, State **and** Licence-num are the primary key^[Yes, we do need the state *and* the licence number to uniquely identify a driver's licence, since [many states use the same licence format](https://ntsi.com/drivers-license-format/).], so they must _together_ satisfy the intergrity constrant: neither of them can be `NULL`. Furthermore, their _pair_ must be different from all the other values. Stated differently, you can have `<GA, 1234>`, `<GA, 0000>` and `<NC, 1234>` as values for the <State, Licence-num> pair, even if they have one element in common, what is forbidden is to have _both_ element in common (i.e., you cannot have `<GA, 1234>` twice). |
|
875 |
|
If both elements were common, that would mean that we are registering a driver that was already in the database. |
|
876 |
|
- Insurance has a primary key, and three foreign keys. The foreign keys must satisfy the referential integrity constraint: if the value stored in Insured-Car is not `NULL` (which it could be), then it has to be a value that occurs as the VIN value of some tuple in the CAR relation. For the Insured-Driver-State and Insured-Driver-Licence-Num, the situation is similar: they must either both be `NULL`, or be values that occurs _paired together_ as the values for State and Licence-Num in a tuple in the CAR relationship. If e.g. Insured-Car was containing the VIN of a car not in the CAR relation, that would mean we are trying to insure a car that is "not known" from the database's perspective, something we certainly want to avoid. |
|
877 |
|
- In Price, we have a primary key and a foreign key that obey similar requirements as before. |
874 |
878 |
|
|
875 |
|
List all the entity integrity constraint and referential integrity constraint. |
|
876 |
|
|
|
877 |
879 |
|
|
878 |
880 |
## Transactions and Operations |
## Transactions and Operations |
879 |
881 |
|
|