Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 更改表中的引用_Postgresql_Foreign Keys - Fatal编程技术网

Postgresql 更改表中的引用

Postgresql 更改表中的引用,postgresql,foreign-keys,Postgresql,Foreign Keys,我有一个表a,它在表B中有外键字段。现在我想将此引用更改为表C。我正在执行以下查询: ALTER TABLE A ALTER COLUMN key_id TYPE integer REFERENCES C(id); 错误获取错误: ERROR: syntax error at or near "REFERENCES" 我怎样才能正确地做呢 谢谢。您应该使用删除约束子句: alter table a drop constraint <constraint_name>; alter

我有一个表
a
,它在表
B
中有外键字段。现在我想将此引用更改为表
C
。我正在执行以下查询:

ALTER TABLE A ALTER COLUMN key_id TYPE integer REFERENCES C(id);
错误获取错误:

ERROR:  syntax error at or near "REFERENCES"
我怎样才能正确地做呢


谢谢。

您应该使用删除约束子句:

alter table a drop constraint <constraint_name>;
alter table a add constraint <constraint_name> foreign key (key_id) references c(id);
改变表格的放置约束;
更改表a添加约束外键(键id)参考c(id);