0

我试图执行以下查询:

1.

CREATE TABLE "PUB"."REGISTRATION"
  (
    "LOGIN_ID"    NUMBER(5,0) NOT NULL ENABLE,
    "LOGIN"       VARCHAR2(120 BYTE) NOT NULL ENABLE,
    "PASSWORD"    VARCHAR2(70 BYTE) NOT NULL ENABLE,
    "FNAME"  VARCHAR2(40 BYTE) NOT NULL ENABLE,
    "MNAME" VARCHAR2(20 BYTE),
    "LNAME"   VARCHAR2(20 BYTE) NOT NULL ENABLE,
    "GENERATEDTIME" DATE NOT NULL ENABLE,
    "LASTUPDATE" DATE,
    "EMAIL"        VARCHAR2(70 BYTE) NOT NULL ENABLE,
    "EMAIL_STATUS" VARCHAR2(20 BYTE),
    "EMAIL_CODE"   VARCHAR2(40 BYTE),
    "DATE_OF_BIRTH" DATE,
    "GENDER" VARCHAR2(20 BYTE),
    CONSTRAINT "USERS_REG_PK" PRIMARY KEY ("LOGIN_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "MYDATA" ENABLE,
    CONSTRAINT "USERS_REG_UK" UNIQUE ("LOGIN") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "MYDATA" ENABLE
  )
  SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
  )
  TABLESPACE "MYDATA" ;

2.

CREATE UNIQUE INDEX "PUB"."USERS_REG_PK" ON "PUB"."REGISTRATION"
  (
    "LOGIN_ID"
  )
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
  )
  TABLESPACE "MYDATA" ;

3.

CREATE UNIQUE INDEX "PUB"."USERS_REG_UK" ON "PUB"."REGISTRATION"
  (
    "LOGIN"
  )
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
  )
  TABLESPACE "MYDATA" ;

表 "PUB"."REGISTRATION" 创建。

运行第二个时出现以下错误:

Error starting at line 29 in command:
CREATE UNIQUE INDEX "PUB"."USERS_REG_PK" ON "PUB"."REGISTRATION"
  (
    "LOGIN_ID"
  )
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE
  (
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT
  )
  TABLESPACE "MYDATA" 
Error at Command Line:29 Column:26
Error report:
SQL Error: ORA-00955: name is already used by an existing object
00955. 00000 -  "name is already used by an existing object"
4

2 回答 2

4

您使用定义的主键约束

CONSTRAINT "USERS_REG_PK" PRIMARY KEY ("LOGIN_ID")

已经创建了一个唯一索引(名称为USERS_REG_PK),因此您会收到重复名称错误。

您无需在已定义为主键的列上创建唯一索引。

于 2013-10-03T13:57:51.807 回答
0

USERS_REG_PK 索引名称已用于主键 login_id 请更改索引名称

于 2013-10-03T13:59:30.640 回答