直观地,将选项 ON UPDATE CASCADE 添加到外键约束将具有使用键的更新值更新所有引用列的效果。那真的有用吗?
从手册中提取的示例:
CREATE TABLE products (
product_no integer PRIMARY KEY,
name text,
price numeric
);
CREATE TABLE orders (
order_id integer PRIMARY KEY,
shipping_address text,
...
);
CREATE TABLE order_items (
product_no integer REFERENCES products ON DELETE RESTRICT,
## HERE'S THE LINE THAT I MODIFIED FROM THE MANUAL, IT USED TO SAY 'ON DELETE CASCADE'
order_id integer REFERENCES orders ON UPDATE CASCADE,
quantity integer,
PRIMARY KEY (product_no, order_id)
);
Run Code Online (Sandbox Code Playgroud)
我正在使用 Postgres 9.1。