- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
ON DELETE CASCADE 会在后续表上触发 ON DELETE 触发器吗?
我有三个表,结果、m_int 和行计数。 M_int 与 FK 的结果相关。结果设置了 ON DELETE CASCADE,m_int 有一个 BEFORE DELETE 触发器。 Rowcount 跟踪 m_int 中使用了多少行以及由哪个用户使用。
我的问题是,当我从结果中删除一行时,我希望 DELETE CASCADE 在 m_int 上触发触发器。有任何想法吗?我整个上午都在阅读文档,但找不到答案。
peri=> \d results
Table "public.results"
Column | Type | Modifiers
-----------+---------+-----------------------------------------------------
result_id | integer | not null default nextval('result_id_seq'::regclass)
trial__id | integer | not null
title | text |
Indexes:
"results_pkey" PRIMARY KEY, btree (result_id)
Referenced by:
TABLE "m_int" CONSTRAINT "m_int_result__id_fkey" FOREIGN KEY (result__id) REFERENCES results(result_id) ON DELETE CASCADE
peri=> \d m_int
Table "public.m_int"
Column | Type | Modifiers
------------+---------+------------------------------------------------------------
metric__id | integer | not null
result__id | integer | not null
value | integer | not null
m_value_id | bigint | not null default nextval('m_int_m_value_id_seq'::regclass)
Indexes:
"m_int_pkey" PRIMARY KEY, btree (m_value_id)
Foreign-key constraints:
"m_int_metric__id_fkey" FOREIGN KEY (metric__id) REFERENCES metrics(metric_id) ON DELETE CASCADE
"m_int_result__id_fkey" FOREIGN KEY (result__id) REFERENCES results(result_id) ON DELETE CASCADE
Triggers:
addrows_m_int AFTER INSERT ON m_int FOR EACH ROW EXECUTE PROCEDURE add_rows_m_int()
remrows_m_int BEFORE DELETE ON m_int FOR EACH ROW EXECUTE PROCEDURE rem_rows_m_int()
peri=> \d rowcount
Table "public.rowcount"
Column | Type | Modifiers
------------+---------+-----------
user__id | integer | not null
table_name | text | not null
total_rows | bigint |
Indexes:
"rowcount_pkey" PRIMARY KEY, btree (user__id, table_name)
最佳答案
手册 CREATE TABLE会告诉你:
In addition, when the data in the referenced columns is changed, certain actions are performed on the data in this table's columns. The ON DELETE clause specifies the action to perform when a referenced row in the referenced table is being deleted. [...]
是的,在 results
中删除也会在 m_int
中删除。当然,这并不意味着在 m_int
中删除会删除 results
中的任何内容。以及您的额外触发器 add_rows_m_int
和 rem_rows_m_int
做什么或阻止什么 - 我们不知道。
关于function - Postgres ON DELETE CASCADE 会在后续表上触发 ON DELETE 触发器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9931600/
我是一名优秀的程序员,十分优秀!