表已以这种方式在系统中创建
CREATE TABLE INSTANCES
(
DM INTEGER NOT NULL,
INSTANCEID VARCHAR2(512) NOT NULL,
INSTANCENAME VARCHAR2(64) NOT NULL UNIQUE,
HOSTNAME VARCHAR2(32) NOT NULL,
CONSTRAINT PK_INSTANCES PRIMARY KEY (INSTANCEID, HOSTNAME)
);
新的 crete table 语句如下:
CREATE TABLE INSTANCES
(
DM INTEGER NOT NULL,
INSTANCEID VARCHAR2(512) NOT NULL UNIQUE,
INSTANCENAME VARCHAR2(64) NOT NULL UNIQUE,
HOSTNAME VARCHAR2(32) NOT NULL,
CONSTRAINT PK_INSTANCES PRIMARY KEY (INSTANCEID, HOSTNAME)
);
不同之处在于 INSTANCEID 具有 UNIQUE。我如何改变桌子?我使用了以下语句,但它对我不起作用。
ALTER TABLE INSTANCES ADD CONSTRAINT ab UNIQUE ( INSTANCEID);
它报错:ALTER TABLE INSTANCES ADD CONSTRAINT ab UNIQUE (INSTANCEID) 错误报告:SQL 错误:ORA-02261: such unique or primary key already exists in the table 02261. 00000 - "such unique or primary key already exists in the table " *原因:不言而喻。*行动:移除额外的钥匙。
请帮我按照上面的要求更改表格。谢谢!
这是 SELECT con.constraint_name, col.column_name, con.constraint_type FROM user_cons_columns col JOIN user_constraints con ON (col.constraint_name = con.constraint_name) WHERE col.table_name = 'INSTANCES' 的输出
"CONSTRAINT_NAME","COLUMN_NAME","CONSTRAINT_TYPE"
"SYS_C0016531","DM","C"
"SYS_C0016532","INSTANCEID","C"
"SYS_C0016533","INSTANCENAME","C"
"SYS_C0016534","HOSTNAME","C"
"PK_INSTANCES","HOSTNAME","P"
"PK_INSTANCES","INSTANCEID","P"
"SYS_C0016536","INSTANCENAME","U"