gpt4 book ai didi

postgresql - Postgres : problem with FK contraint

转载 作者:行者123 更新时间:2023-11-29 14:24:43 25 4
gpt4 key购买 nike

如何解决 FK 约束?带触发器还是其他东西?

#IF "DELETE FROM human where name='a';", error due to the FK contraist.

# If the error, I want in the order:
# FIRSTLY. DELETE FROM address where name='a';
# SECONDLY. DELETE FROM human where name='a';


DROP TABLE human;
DROP TABLE address;

CREATE TABLE human(
name varchar(300) PRIMARY KEY not null

);

CREATE TABLE address(
name varchar(300)
references human.name

);

最佳答案

CREATE TABLE address (
name varchar(300) REFERENCES human (name) ON DELETE CASCADE
);

这是你想要的吗?

关于postgresql - Postgres : problem with FK contraint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1356447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com