Skip to main content

PostGres - Advanced

Lesson Objectives - important#

  1. Joins
  2. Linking Tables
  3. Alias
  4. Indexes
  5. Constraints

Lesson Objectives - good to know about#

  1. EER Diagrams
  2. Unions
  3. Truncate
  4. Triggers
  5. Views
  6. Functions/Stored Procedures
  7. Transactions
  8. Locks
  9. Privileges
  10. Denormalization
  11. Excel -> CSV -> MySQL

Important#

Joins#

  1. Cross Join
  2. Inner Join
  3. Left Join
  4. Right Join
  5. Full Join
SELECT table1.column1, table2.column2FROM table1INNER JOIN table2ON table1.common_filed = table2.common_field;

Linking Tables#

  1. http://code.tutsplus.com/articles/sql-for-beginners-part-3-database-relationships--net-8561
  2. One to One Relationships
  • each user has one address
  • only one person at that address
  1. One to Many/Many to One Relationships
  • customer has many orders
  1. Many to Many Relationships
  • actors and movies
  1. Self Referncing Relationships
  • customer referral

Alias#

SELECT t1.column1 as col1, t2.column2 as col2FROM table1 as t1INNER JOIN table2 as t2ON t1.common_filed = t2.common_field;

Indexes#

  1. CREATE INDEX index_name ON table_name (column_name);
  2. CREATE INDEX index_name ON table_name (column1_name, column2_name);
  3. Primary Key

Constraints#

  1. NOT NULL
  2. Unique
  3. Foreign Keys
CREATE TABLE companies(  id          SERIAL       PRIMARY KEY,  name        VARCHAR(16)  NOT NULL UNIQUE,  city        VARCHAR(16));INSERT INTO companies ( city ) VALUES ('Palo Alto');CREATE TABLE people(  id          INT          PRIMARY KEY,  name        VARCHAR(16)  NOT NULL,  email       VARCHAR(32)  NOT NULL UNIQUE,  company_id  INT          REFERENCES companies(id));

Good to Know About#

EER Diagrams#

Unions#

Truncate#

Triggers#

Views#

Functions/Stored Procedures#

Transactions#

Locks#

Privileges#

Denormalization#

Excel -> CSV -> MySQL#

SQL Injection#