我正在为postgres手动构造一个DELETE CASCADE语句.
我有一个"事务"和一个"切片"表,如下所示:
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_slice"的切片引用的所有事务和分类_项.我需要写什么?
=# delete from classification_item where transaction_id= #...?
=# delete from transaction where slice_id= #...?
=# delete from slice where name='my_slice';