简体   繁体   English

如何删除未命名的主键约束

[英]how to drop unnamed primary key constraint

i created a table in oracle 10g as following : 我在oracle 10g中创建了一个表,如下所示:

CREATE TABLE studentTbl(
 studId VARCHAR2(20) PRIMARY KEY,
 StudName VARCHAR2(40)
 );

And now want to remove primary key from studId without dropping this column. 现在想要从studId中删除主键而不删除此列。 I searched about it and found Dropping unnamed constraints but it also could n't help me. 我搜索了它并找到了Dropping未命名的约束,但它也无法帮助我。 Couldn't get sys.columns table or view. 无法获取sys.columns表或视图。

Thanks 谢谢

alter table studenttbl drop primary key;

More details in the manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_3001.htm#i2103997 手册中的更多细节: http//docs.oracle.com/cd/E11882_01/server.112/e26088/statements_3001.htm#i2103997

(What is this tbl suffix for? Sounds like a terrible naming convention) (这个tbl后缀是什么?听起来像一个可怕的命名约定)

The question you link to isn't for Oracle. 您链接的问题不适用于Oracle。 The system view USER_CONSTRAINTS has a list of all constraints. 系统视图USER_CONSTRAINTS具有所有约束的列表。 The P in the CONSTRAINT_TYPE column indicates that it's a primary key; CONSTRAINT_TYPE列中的P表示它是主键; you can utilise this to find other constraints. 你可以利用它来找到其他约束。

You can use this view to generate the DDL necessary to drop the constraint (or to view other information). 您可以使用此视图生成删除约束(或查看其他信息)所需的DDL。

For example: 例如:

CREATE TABLE studentTbl(
 studId VARCHAR2(20) PRIMARY KEY,
 StudName VARCHAR2(40)
 );

Table created.


select 'alter table ' || table_name
       || ' drop constraint ' || constraint_name || ';'
  from user_constraints
 where table_name = 'STUDENTTBL'
   and constraint_type = 'P';

'ALTERTABLE'||TABLE_NAME||'DROPCONSTRAINT'||CONSTRAINT_NAME||';'
----------------------------------------------------------------------

alter table STUDENTTBL drop constraint SYS_C0017725;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM