如何删除主键或外键? [英] How can I delete a primary or foreign key?

查看:110
本文介绍了如何删除主键或外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PostgreSQL 7.4.1(仅通过psql)

我知道,该命令


ALTER TABLE OFFICES

DROP PRIMARY KEY(CITY);


及其等效的外键:


ALTER TABLE SALESREPS

DROP CONSTRAINT

FOREIGN KEY(REP_OFFICE)

参考办公室;


不能在PostgreSQL中工作,因为它们没有实现。但是,有没有另外一种方法可以删除它们?

我也尝试删除与主键关联的索引,但它不是
允许$​​ b $ b。


有任何想法的人吗?

-

Tibor


---------------------------(播出结束)-------------- -------------

提示8:解释分析是你的朋友

解决方案



2004年2月20日星期五,Tibor写道:

我正在使用PostgreSQL 7.4.1(仅通过psql)
我知道,那个命令

ALTER TABLE OFFICES
DROP PRIMARY KEY(CITY);

及其外键等价物:

ALTER TABLE SALESREPS
DROP CONSTRAINT
FOREIGN KEY(REP_OFFICE)
参考办公室;

不能在PostgreSQL中工作,因为它们没有实现。但是,还有其他方法可以删除它们吗?




这不是ALTER TABLE ... DROP CONSTRAINT的正确语法。


ALTER TABLE tablename DROP CONSTRAINT constraint_name [RESTRICT | CASCADE]

---------------------------(广播结束)-------- -------------------

提示8:解释分析是你的朋友

2004年2月20日星期五,Tibor写道:

我正在使用PostgreSQL 7.4.1(仅通过psql)
我知道,该命令

ALTER TABLE OFFICES
DROP PRIMARY KEY(CITY);

及其外键等价物:

ALTER TABLE SALESREPS
DROP约束
外键(REP_OFFICE)
参考办公室;

不能在PostgreSQL中工作,因为它们没有实现。但是,有没有另外一种方法可以删除它们?
我还试图删除与主键相关的索引,但它不被允许。

任何有想法的人?




这是一个转换表:

alter table offices drop constraint constraint_name


其中约束名称通常是tablename_pkey


假设它是在7.4盒子上以正常方式创建的。

---------------------------(广播结束)------------------ ---------

提示8:解释分析是你的朋友


我忘了提到我已尝试过多种变化。

原始邮件中引用的邮件来自The Complete Reference。系列。

我也尝试了\h命令建议的那个:


ALTER TABLE PARENTS DROP CONSTRAINT FOREIGN KEY(TYPE)CASCADE;


但我得到的只是:


错误:语法错误在或接近外国在角色37


DROP CONSTRAINT子句无法识别PRIMARY或FOREIGN KEY

选项。 (未实现,我猜)


2004年2月20日星期五16:42,你写道:

2004年2月20日星期五,Tibor写道:< blockquote class =post_quotes>我正在使用PostgreSQL 7.4.1(仅通过psql)
我知道,那个命令

ALTER TABLE OFFICES
DROP PRIMARY KEY(CITY) ;

及其外键等价物:

ALTER TABLE SALESREPS
DROP CONSTRAINT
外键(REP_OFFICE)
参考办公室;

不能在PostgreSQL中工作,因为它们没有实现。但是,有没有另外一种方法可以删除它们?



这不是ALTER TABLE ... DROP CONSTRAINT的正确语法。

ALTER TABLE tablename DROP CONSTRAINT constraint_name [RESTRICT | CASCADE]




-

Tibor


--------- ------------------(广播结束)---------------------------

提示3:如果通过Usenet发布/阅读,请将相应的

subscribe-nomail命令发送到 ma ******* @ postgresql.org 这样你的

消息就可以干净利落地进入邮件列表


I am using PostgreSQL 7.4.1 (only through psql)
I know, that the command

ALTER TABLE OFFICES
DROP PRIMARY KEY (CITY);

and its foreign key equivalent:

ALTER TABLE SALESREPS
DROP CONSTRAINT
FOREIGN KEY (REP_OFFICE)
REFERENCES OFFICES;

don''t work in PostgreSQL because they are not implemented. However, isn''t
there another way of removing them?
I also tried to drop the index associated with the primary key, but it is not
permitted.

Anyone with any idea?
--
Tibor

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

解决方案


On Fri, 20 Feb 2004, Tibor wrote:

I am using PostgreSQL 7.4.1 (only through psql)
I know, that the command

ALTER TABLE OFFICES
DROP PRIMARY KEY (CITY);

and its foreign key equivalent:

ALTER TABLE SALESREPS
DROP CONSTRAINT
FOREIGN KEY (REP_OFFICE)
REFERENCES OFFICES;

don''t work in PostgreSQL because they are not implemented. However, isn''t
there another way of removing them?



That''s not the correct syntax for ALTER TABLE ... DROP CONSTRAINT.

ALTER TABLE tablename DROP CONSTRAINT constraint_name [RESTRICT | CASCADE]
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


On Fri, 20 Feb 2004, Tibor wrote:

I am using PostgreSQL 7.4.1 (only through psql)
I know, that the command

ALTER TABLE OFFICES
DROP PRIMARY KEY (CITY);

and its foreign key equivalent:

ALTER TABLE SALESREPS
DROP CONSTRAINT
FOREIGN KEY (REP_OFFICE)
REFERENCES OFFICES;

don''t work in PostgreSQL because they are not implemented. However, isn''t
there another way of removing them?
I also tried to drop the index associated with the primary key, but it is not
permitted.

Anyone with any idea?



It''s an alter table:

alter table offices drop constraint constraint_name

where constraint name is usually tablename_pkey

assuming it was created the normal way, on a 7.4 box.
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


I forgot to mention that I have tried numerous variations.
The one quoted in the original mail was from "The Complete Reference" series.
I''ve also tried the one that the \h command suggests:

ALTER TABLE PARENTS DROP CONSTRAINT FOREIGN KEY (TYPE) CASCADE;

but all I got was:

ERROR: syntax error at or near "foreign" at character 37

the DROP CONSTRAINT clause doesn''t recognise either PRIMARY or FOREIGN KEY
option. (not implemented, I guess)

On Friday 20 Feb 2004 16:42, you wrote:

On Fri, 20 Feb 2004, Tibor wrote:

I am using PostgreSQL 7.4.1 (only through psql)
I know, that the command

ALTER TABLE OFFICES
DROP PRIMARY KEY (CITY);

and its foreign key equivalent:

ALTER TABLE SALESREPS
DROP CONSTRAINT
FOREIGN KEY (REP_OFFICE)
REFERENCES OFFICES;

don''t work in PostgreSQL because they are not implemented. However, isn''t
there another way of removing them?



That''s not the correct syntax for ALTER TABLE ... DROP CONSTRAINT.

ALTER TABLE tablename DROP CONSTRAINT constraint_name [RESTRICT | CASCADE]



--
Tibor

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly


这篇关于如何删除主键或外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆