Skip to content

Commit

Permalink
notes
Browse files Browse the repository at this point in the history
  • Loading branch information
asboyer committed Jun 18, 2024
1 parent c478c74 commit e5f2c89
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions _notes/2024-06-18-sql-course.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ As the structure becomes more complex, it becomes more difficult to get specific
---

Tables
:Have columns, rows
: Have columns, rows
Columns
: categories
Rows
Expand All @@ -89,7 +89,28 @@ Primary key
![image](/assets/img/notes/primary_key.png)
How to discern between the Jacks? \
*Primary key* is different. *Always* going to be unique for each row in the table \
Can be anything (str, int, etc.), as long as its unique
Can be anything (str, int, etc.), as long as its unique \

#### Types of Primary keys

1. Surrogate key
: key that has no mapping to anything in real world (random)

2. Natural key
: ex: social security number

3. Foreign key
: stores the primary key of a row in another database table

#### Foreign key example:
`branch_id` maps to a row in the **Branch** database
![image](/assets/img/notes/foreign_key_1.png)
![image](/assets/img/notes/foreign_key_2.png)

**Note**: can have multiple foreign keys \
Can also use foreign key to map to another row in the same table \
Can define a **composite key** to define a key that uses multiple columns to combine to make a primary key. \
ie: two columns uniquely defining a row to make a primary key

---

Expand Down
Binary file added assets/img/notes/foreign_key_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/notes/foreign_key_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5f2c89

Please sign in to comment.