Create a table that references another table

suggest change

In this example, the users table has a column that references the agencies table. Create the referenced table first.

CREATE TABLE agencies (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL
);

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  agency_id INTEGER NOT NULL REFERENCES agencies(id) DEFERRABLE INITIALLY DEFERRED
);

Feedback about page:

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



Table Of Contents