📜  postgresql 删除级联 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:05:09.859000             🧑  作者: Mango

代码示例1
CREATE TABLE employee(emp_id SERIAL PRIMARY  KEY, name VARCHAR(30),
    sector_fk INT NOT NULL);

CREATE TABLE process(emp_id SERIAL PRIMARY KEY, sector VARCHAR(20));

ALTER TABLE employee ADD FOREIGN KEY (sector_fk)
REFERENCES company(emp_id) ON DELETE CASCADE;

-- Deletes cascade employees referencing deleted companies
DELETE FROM company WHERE sector='industry';