[英]How to fix “ORA-01735: Invalid ALTER TABLE option” error in Oracle11g
I'm coding a SQL script but, when I compile and try execute with SQL*PLUS, this show mentioned error at beginning of the issue. 我正在编码一个SQL脚本,但是,当我编译并尝试使用SQL * PLUS执行时,此显示在问题开始时提到了错误。 I'm seeing other related issues but I can't find the solution.
我看到了其他相关问题,但找不到解决方案。
This is for a local server in my Windows 10' computer, running Oracle 11g with SQL*PLUS and XAMPP Server. 这用于Windows 10'计算机中的本地服务器,该服务器运行带有SQL * PLUS和XAMPP Server的Oracle 11g。 I've tried on another computer with similar specificatios except specific details.
我在另一台具有类似规格的计算机上尝试过,但具体细节除外。
ALTER TABLE ACTORES(
ADD CONSTRAINT pk_actores PRIMARY KEY (Codigo)
);
COMMIT;
ALTER TABLE PERSONAJES(
ADD CONSTRAINT pk_personajes PRIMARY KEY (Codigo),
ADD CONSTRAINT fk1_personajes FOREIGN KEY (CodigoActor) REFERENCES ACTORES (Codigo),
ADD CONSTRAINT fk2_personajes FOREIGN KEY (CodigoSuperior) REFERENCES PERSONAJES (Codigo)
);
COMMIT;
ALTER TABLE NAVES(
ADD CONSTRAINT pk_naves PRIMARY KEY (Codigo)
);
COMMIT;
Too many parenthesis aren't healthy . 太多括号是不健康的 。
SQL> create table actores (codigo number);
Table created.
SQL> alter table actores (add constraint pk_actores primary key (codigo));
alter table actores (add constraint pk_actores primary key (codigo))
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option
SQL> alter table actores add constraint pk_actores primary key (codigo);
Table altered.
SQL>
Another table: 另一张桌子:
SQL> create table personajes (codigo number, codigoactor number, codigosuperior number);
Table created.
SQL> alter table personajes add constraint pk_personajes primary key (codigo);
Table altered.
SQL> alter table personajes add constraint fk1_personajes foreign key (codigoactor)
2 references actores (codigo);
Table altered.
SQL> alter table personajes add constraint fk2_personajes foreign key (codigosuperior)
2 references personajes (codigo);
Table altered.
SQL>
Or, alternatively, several constraints in the same ALTER TABLE
: 或者,在同一
ALTER TABLE
几个约束:
SQL> drop table personajes;
Table dropped.
SQL> create table personajes (codigo number, codigoactor number, codigosuperior number);
Table created.
SQL> alter table personajes add
2 (constraint pk_personajes primary key (codigo),
3 constraint fk1_personajes foreign key (codigoactor)
4 references actores (codigo),
5 constraint fk2_personajes foreign key (codigosuperior)
6 references personajes (codigo)
7 );
Table altered.
SQL>
Do the same for the rest of your tables/constraints. 对其余的表/约束执行相同的操作。
PS Oh, yes - you don't have to COMMIT
; PS哦,是的-您不必
COMMIT
; ALTER TABLE
is DDL and implicitly commits any changes. ALTER TABLE
是DDL,并且隐式提交任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.