Skip to content

Instantly share code, notes, and snippets.

@ebectar
Last active May 24, 2018 18:54
Show Gist options
  • Save ebectar/c3e114fe895b151cfa00a36c785cfbe5 to your computer and use it in GitHub Desktop.
Save ebectar/c3e114fe895b151cfa00a36c785cfbe5 to your computer and use it in GitHub Desktop.
**Primary Key** - must be unique, something that is not reproduced anywhere else in a table; can be used to reference this table in other tables
**Foreign Key** - key used from another table
**table relationships**
- 1 to 1 (character to wand)
- 1 to many (character can only be in one house, house can have many characters)
- many to many (characters to books, character in multiple books, one book has multiple characters)
**Entity Relationship Diagram**
______________________________
| characters |
|______________________________|
| | | |
| PK | id | serial |
| | name | varchar |
| FK | house | number | >-----
------------------------------ |
|
_________________________________ |
| houses | |
|_________________________________| |
| | | | |
| PK | id | serial |-|--
| | house | varchar |
| | founder | varchar |
---------------------------------
**Creating a Join**
Select = Read (can create, insert, etc)
* - all columns
from <table name>
join <table name>
on <matching-ids>
```select * from characters on characters.house = houses.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment