PostgreSQL_Notes


Project maintained by Kellen-Linse Hosted on GitHub Pages — Theme by mattgraham

Working with Tables



The Plan Moving Forwards


Approach to Database Design

photo

What tables should we make?

instagram

Relationships

The four relationships:

  1. One-to-Many
    • User to Photos
    • From the perspective of the user.
    • There can be many photos, but they can only belong to one user.

one to many

  1. Many-to-One
    • There can be many photos, but they can only belong to one user.
    • From the perspective of the photos.

otm

  1. One-to-One
    • One record that has a relationship to exactly one other relationship.

one

  1. Many-to-Many
    • Many records connected to many other records.

many

Primary Keys and Foreign Keys

keys

Understanding Foreign Keys

The ‘many’ side of the relationship gets the foreign key column.

Auto-Generated ID’s

pg-vis

Creating Foreign Key Columns

pg vis

Running Queries on Associated Data

Two ways we can retrieve the photos for a given user:

data q

Foreign Key Constraints Around Data Insertion

insert error


null

Constraints Around Deletion

delete options

Setting Delete Options

setting delete options

« PREV - HOME - NEXT »