删除唯一键并生成新的唯一键

时间:2012-05-04 07:09:14

标签: oracle11g

我在oracle数据库中创建了一个表,我的表脚本是

  CREATE TABLE wsc_widget_bundle (
    id VARCHAR (50),
    widgetBundle BLOB NULL, 
    devicesoftwareclass VARCHAR(30) NOT NULL,
    widgetProfileId VARCHAR (50) NOT NULL,
    bundleHash BLOB NULL,
    widgetLocale VARCHAR (6) NOT NULL ,
    status INT,  
        primary key(id),
        unique(widgetProfileId, devicesoftwareclass,status),
    foreign key(widgetProfileId) references wsc_widget_profile(id)
  );

当我创建ddl时,它看起来像

create table "DEV1"."WSC_WIDGET_BUNDLE"(
    "ID" VARCHAR2(50) not null,
   "WIDGETBUNDLE" BLOB,
   "DEVICESOFTWARECLASS" VARCHAR2(30) not null,
   "WIDGETPROFILEID" VARCHAR2(50) not null,
   "BUNDLEHASH" BLOB,
   "WIDGETLOCALE" VARCHAR2(6) not null,
   "STATUS" NUMBER,
    constraint "SYS_C00323290" primary key ("ID")
);

alter table "DEV1"."WSC_WIDGET_BUNDLE"  
    add constraint "SYS_C00323292" 
    foreign key ("WIDGETPROFILEID") 
    references "MTP440_DEV1"."WSC_WIDGET_PROFILE"("ID");
create unique index "MTP440_DEV1"."SYS_C00323290" on "MTP440_DEV1"."WSC_WIDGET_BUNDLE"("ID");
create unique index "MTP440_DEV1"."SYS_C00323291" on "MTP440_DEV1"."WSC_WIDGET_BUNDLE"("WIDGETPROFILEID","DEVICESOFTWARECLASS","STATUS");
create index "MTP440_DEV1"."TEST" on "MTP440_DEV1"."WSC_WIDGET_BUNDLE"("DEVICESOFTWARECLASS","STATUS","WIDGETLOCALE","WIDGETPROFILEID");

现在我想编写alter script来改变我的表的唯一键约束但是在创建表时我没有提到我的唯一键名的名称,它是由系统给出的,如SYS_C00323291 那么我怎样才能编写alter script来删除那个名字不为我所知并且生成新的

的唯一键

2 个答案:

答案 0 :(得分:0)

Alter table x
drop constraint pk;

Alter table x
add constraint New_constraint_name PRIMARY KEY (colname);

答案 1 :(得分:0)

您可以通过查询user_constraints和user_cons_columns视图来查找约束的名称。