Create a table that references other table

suggest change

In this example, User Table will have a column that references the Agency table.

CREATE TABLE agencies ( -- first create the agency table
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL
)

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  agency_id NOT NULL INTEGER REFERENCES agencies(id) DEFERRABLE INITIALLY DEFERRED -- this is going to references your agency table.
)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents