You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.8 KiB

PostGres - Advanced

Lesson Objectives - important

  1. Linking Tables
  2. Alias
  3. Indexes
  4. 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

Linking Tables

  1. Some Nice Visuals
  2. One to Many/Many to One Relationships
    • customer has many orders
  3. One to One Relationships
    • each user has one address
    • only one person at that address
  4. Many to Many Relationships
    • actors and movies
  5. Self Referncing Relationships
    • customer referral

Alias

SELECT t1.column1 as col1, t2.column2 as col2
FROM table1 as t1
INNER JOIN table2 as t2
ON 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. use \d table_name to view indexes
  4. 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)
);
INSERT INTO people (name, email, company_id) VALUES ('bob', 'bob@bob.com', 999)

Good to Know About

EER Diagrams

Unions

Truncate

Triggers

Views

Functions/Stored Procedures

Transactions

Locks

Privileges

Denormalization

Excel -> CSV -> MySQL

SQL Injection