我正在为postgres手动构造一个DELETE CASCADE语句。
我有一个'transaction‘和一个'slice’表,相关如下所示:
Table "public.slice"
Column | Type | Modifiers
----------+------+-----------
id | text | not null
name | text |
Referenced by:
TABLE "transaction" CONSTRAINT "transaction_slice_id_fkey" FOREIGN KEY (slice_id) REFERENCES slice(id)
Table "public.transaction"
Column | Type | Modifiers
----------+------+-----------
id | text | not null
slice_id | text |
Referenced by:
TABLE "classification_item" CONSTRAINT "classification_item_transaction_id_fkey" FOREIGN KEY (transaction_id) REFERENCES transaction(id)
Table "public.classification_item"
Column | Type | Modifiers
----------------+------+-----------
id | text | not null
transaction_id | text |
Foreign-key constraints:
"classification_item_transaction_id_fkey" FOREIGN KEY (transaction_id) REFERENCES transaction(id)假设我想删除由名为‘my_ classification_items’的切片引用的所有事务和切片。我需要写些什么?
=# delete from classification_item where transaction_id= #...?
=# delete from transaction where slice_id= #...?
=# delete from slice where name='my_slice';发布于 2010-09-15 03:58:01
Postgres外键支持级联删除:
slice_id integer REFERENCES slice(id) ON DELETE CASCADE等
https://stackoverflow.com/questions/3711580
复制相似问题