创建一个引用其他表的表
在此示例中,用户表将具有引用 Agency 表的列。
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.
)