Skip to content

Commit c060897

Browse files
committed
Create readme.md
1 parent fcf941b commit c060897

File tree

5 files changed

+88
-0
lines changed
  • Introduction to Relational Databases in SQL
    • 01 Your first database/01 Attributes of relational databases
    • 02 Enforce data consistency with attribute constraints
    • 03 Uniquely identify records with key constraints/03 Identify the primary key
    • 04 Glue together tables with foreign keys/07 Referential integrity violations

5 files changed

+88
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Attributes of relational databases
2+
3+
In the video, we talked about some basic facts about relational databases. Which of the following statements does not hold true for databases? Relational databases ...
4+
5+
**Possible Answers**
6+
7+
* ... store different real-world entities in different tables.
8+
* ... allow to establish relationships between entities.
9+
* ... are called "relational" because they store data only about people.
10+
* ... use constraints, keys and referential integrity in order to assure data quality.
11+
12+
**Answer**
13+
14+
> ... are called "relational" because they store data only about people.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Calculate the net amount as amount + fee
2+
-- SELECT transaction_date, amount + fee AS net_amount
3+
SELECT transaction_date, amount + CAST(fee AS integer) AS net_amount
4+
FROM transactions;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## What happens if you try to enter NULLs?
2+
3+
Execute the following statement:
4+
5+
```
6+
INSERT INTO professors (firstname, lastname, university_shortname)
7+
VALUES (NULL, 'Miller', 'ETH');
8+
```
9+
10+
<hr>
11+
12+
Why does this throw an error?
13+
14+
**Possible Answers**
15+
16+
* Professors without first names do not exist.
17+
* Because a database constraint is violated.
18+
* Error? This works just fine.
19+
* `NULL` is not put in quotes.
20+
21+
**Answer**
22+
23+
> Because a database constraint is violated.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## Identify the primary key
2+
3+
Have a look at the example table from the previous video. As the database designer, you have to make a wise choice as to which column should be the primary key.
4+
5+
```
6+
license_no | serial_no | make | model | year
7+
--------------------+-----------+------------+---------+------
8+
Texas ABC-739 | A69352 | Ford | Mustang | 2
9+
Florida TVP-347 | B43696 | Oldsmobile | Cutlass | 5
10+
New York MPO-22 | X83554 | Oldsmobile | Delta | 1
11+
California 432-TFY | C43742 | Mercedes | 190-D | 99
12+
California RSK-629 | Y82935 | Toyota | Camry | 4
13+
Texas RSK-629 | U028365 | Jaguar | XJS | 4
14+
```
15+
16+
<hr>
17+
18+
Which of the following column or column combinations could best serve as primary key?
19+
20+
**Possible Answers**
21+
22+
* PK = {make}
23+
* PK = {model, year}
24+
* PK = {license_no}
25+
* PK = {year, make}
26+
27+
**Answer**
28+
29+
> PK = {license_no}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Referential integrity violations
2+
3+
Given the current state of your database, what happens if you execute the following SQL statement?
4+
5+
```
6+
DELETE FROM universities WHERE id = 'EPF';
7+
```
8+
9+
**Possible Answers**
10+
11+
* It throws an error because the university with ID "EPF" does not exist.
12+
* The university with ID "EPF" is deleted.
13+
* It fails because referential integrity from `universities` to `professors` is violated.
14+
* It fails because referential integrity from `professors` to `universities` is violated.
15+
16+
**Answer**
17+
18+
> It fails because referential integrity from `professors` to `universities` is violated.

0 commit comments

Comments
 (0)