updates to important

main
Matthew Huntington 2 years ago
parent 203c742af5
commit 6c695b1dec

Binary file not shown.

@ -1,13 +1,14 @@
# PostGres - Advanced # PostGres - Advanced
## Lesson Objectives - important ## Lesson Objectives - important
1. Joins
1. Linking Tables 1. Linking Tables
1. Alias 1. Alias
1. Indexes 1. Indexes
1. Constraints 1. Constraints
## Lesson Objectives - good to know about ## Lesson Objectives - good to know about
1. EER Diagrams 1. EER Diagrams
1. Unions 1. Unions
1. Truncate 1. Truncate
@ -22,32 +23,21 @@
## Important ## Important
### Joins
1. Cross Join
1. Inner Join
1. Left Join
1. Right Join
1. Full Join
```sql
SELECT table1.column1, table2.column2
FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field;
```
### Linking Tables ### Linking Tables
1. `http://code.tutsplus.com/articles/sql-for-beginners-part-3-database-relationships--net-8561`
1. [Some Nice Visuals](http://code.tutsplus.com/articles/sql-for-beginners-part-3-database-relationships--net-8561)
1. One to Many/Many to One Relationships
- customer has many orders
1. One to One Relationships 1. One to One Relationships
- each user has one address - each user has one address
- only one person at that address - only one person at that address
1. One to Many/Many to One Relationships
- customer has many orders
1. Many to Many Relationships 1. Many to Many Relationships
- actors and movies - actors and movies
1. Self Referncing Relationships 1. Self Referncing Relationships
- customer referral - customer referral
### Alias ### Alias
```sql ```sql
SELECT t1.column1 as col1, t2.column2 as col2 SELECT t1.column1 as col1, t2.column2 as col2
FROM table1 as t1 FROM table1 as t1
@ -56,14 +46,18 @@ ON t1.common_filed = t2.common_field;
``` ```
### Indexes ### Indexes
1. `CREATE INDEX index_name ON table_name (column_name);` 1. `CREATE INDEX index_name ON table_name (column_name);`
1. `CREATE INDEX index_name ON table_name (column1_name, column2_name);` 1. `CREATE INDEX index_name ON table_name (column1_name, column2_name);`
1. use `\d table_name` to view indexes
1. Primary Key 1. Primary Key
### Constraints ### Constraints
1. NOT NULL 1. NOT NULL
1. Unique 1. Unique
1. Foreign Keys 1. Foreign Keys
```sql ```sql
CREATE TABLE companies( CREATE TABLE companies(
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
@ -77,6 +71,7 @@ CREATE TABLE people(
email VARCHAR(32) NOT NULL UNIQUE, email VARCHAR(32) NOT NULL UNIQUE,
company_id INT REFERENCES companies(id) company_id INT REFERENCES companies(id)
); );
INSERT INTO people (name, email, company_id) VALUES ('bob', 'bob@bob.com', 999)
``` ```
## Good to Know About ## Good to Know About

Loading…
Cancel
Save