-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
570 changed files
with
57,579 additions
and
1,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
--- | ||
title: "CS134-lecture-20210608" | ||
# date: 2021-06-08T16:12:49-07:00 | ||
draft: false | ||
bookToc: true | ||
tags: ["relational model", "keys"] | ||
--- | ||
|
||
## RE assignment 1 | ||
|
||
`account_number` is a unique value. | ||
|
||
## Relational model cont. | ||
|
||
### State cont. | ||
|
||
![image_2021-06-08-16-14-58](/notes/image_2021-06-08-16-14-58.png) | ||
|
||
``` | ||
R(color, bit) | ||
dom(color) = {blue, green, red} | ||
dom(bit) = {0, 1} | ||
``` | ||
|
||
color | bit | ||
--- | --- | ||
blue | 0 | ||
blue | 1 | ||
green | 0 | ||
green | 1 | ||
red | 0 | ||
red | 1 | ||
|
||
This is all the possible combinations, but lets say we have a state like | ||
|
||
color | bit | ||
--- | --- | ||
blue | 1 | ||
green | 0 | ||
|
||
Which visualizes that the state is a subset of all possible combinations. | ||
|
||
### Specifying an attribute's value | ||
|
||
![image_2021-06-08-16-23-38](/notes/image_2021-06-08-16-23-38.png) | ||
|
||
### Constraints | ||
|
||
![image_2021-06-08-16-22-51](/notes/image_2021-06-08-16-22-51.png) | ||
|
||
As a programmer we don't have much of selection when it comes to model-based constraints. | ||
|
||
![image_2021-06-08-16-22-58](/notes/image_2021-06-08-16-22-58.png) | ||
|
||
DDL = date definition language | ||
|
||
{{< hint info >}} | ||
Note: We are not currently covering data dependencies. | ||
{{< /hint >}} | ||
|
||
![image_2021-06-08-16-37-49](/notes/image_2021-06-08-16-37-49.png) | ||
![image_2021-06-08-16-38-40](/notes/image_2021-06-08-16-38-40.png) | ||
|
||
### Key constraints | ||
|
||
![image_2021-06-08-16-39-11](/notes/image_2021-06-08-16-39-11.png) | ||
|
||
Versus a key, superkeys do not have to be minimal. | ||
|
||
![image_2021-06-08-16-49-17](/notes/image_2021-06-08-16-49-17.png) | ||
|
||
- `{ssn, name}` is a superkey | ||
- `{building, room_no}` is a key, and a superkey | ||
|
||
True or false | ||
|
||
- Any superkey is a key | ||
- false | ||
- Any key is a superkey | ||
- true | ||
|
||
### Primary key | ||
|
||
![image_2021-06-08-16-59-41](/notes/image_2021-06-08-16-59-41.png) | ||
|
||
We have two candidate keys `license_number` and `engine_serial_number`. | ||
We will need to pick 1 to be the primary key. | ||
|
||
![image_2021-06-08-17-00-18](/notes/image_2021-06-08-17-00-18.png) | ||
|
||
{{< hint info >}} | ||
Note on notation in relational model: we only underline the primary key. | ||
{{< /hint >}} | ||
|
||
### Constraints on null values | ||
|
||
![image_2021-06-08-17-03-55](/notes/image_2021-06-08-17-03-55.png) | ||
|
||
### Entity integrity constraint | ||
|
||
![image_2021-06-08-17-07-14](/notes/image_2021-06-08-17-07-14.png) | ||
|
||
### Multiple relations – referential integrity constraints | ||
|
||
![image_2021-06-08-17-08-46](/notes/image_2021-06-08-17-08-46.png) | ||
|
||
### Foreign keys | ||
|
||
![image_2021-06-08-17-11-11](/notes/image_2021-06-08-17-11-11.png) | ||
|
||
Foreign keys can be | ||
|
||
- 1 attributes | ||
- or, {{<k>}} n {{</k>}} attributes | ||
|
||
The foreign key must | ||
|
||
- have the same domain as the primary keys on the *other* schema. | ||
- obey `t1[foreign] = t2[primary]` | ||
|
||
![image_2021-06-08-17-15-00](/notes/image_2021-06-08-17-15-00.png) | ||
![image_2021-06-08-17-15-20](/notes/image_2021-06-08-17-15-20.png) | ||
|
||
`DNO` {{<k>}} \to {{</k>}} `DNUMBER` is a foreign key with 1 attribute | ||
|
||
![image_2021-06-08-17-18-52](/notes/image_2021-06-08-17-18-52.png) | ||
|
||
Remember, to be a foreign key, we need to verify that `DNO` and `DNUMBER` have the same domain. | ||
They do not have to have the same name. | ||
|
||
If we change the requirement so that employees don't have to work for a department, the keys must reference to existing attributes: | ||
|
||
![image_2021-06-08-17-21-41](/notes/image_2021-06-08-17-21-41.png) | ||
|
||
But if we have an employee that doesn't have a department, we must put a null value: | ||
|
||
![image_2021-06-08-17-22-00](/notes/image_2021-06-08-17-22-00.png) | ||
|
||
Another example of a foreign key: | ||
|
||
![image_2021-06-08-17-24-42](/notes/image_2021-06-08-17-24-42.png) | ||
|
||
Notice that foreign keys create duplication among tuples. | ||
|
||
![image_2021-06-08-17-28-17](/notes/image_2021-06-08-17-28-17.png) | ||
![image_2021-06-08-18-00-50](/notes/image_2021-06-08-18-00-50.png) | ||
|
||
### Application based constraints | ||
|
||
![image_2021-06-08-18-09-29](/notes/image_2021-06-08-18-09-29.png) | ||
|
||
Triggers and assertions are part of SQL. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.