문제

I've tried searching this topic, and my searches led me to this format, which is still throwing an error. When I execute my script, I basically get a load of ORA-01735 errors for all my later statements. I had it done out differently, but googling led me to this format, which still doesn't work. Any tips?

CREATE TABLE table7
(
column1 int NOT NULL,
column2 int NOT NULL,
column3 int NOT NULL
)
/

ALTER TABLE table7

ADD(    pk1 PRIMARY KEY(column1),
    fk1 FOREIGN KEY(column2) REFERENCES Table1(column2),
    fk2 FOREIGN KEY(column3) REFERENCES Service(column3)
)
/
도움이 되었습니까?

해결책

ADD should surround each column definition. You don't wrap a single ADD around 3 new columns.

See: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_3001.htm#i2183462

For Primary Key and Foreign Key constraints you need the CONSTRAINT keyword. See: http://docs.oracle.com/javadb/10.3.3.0/ref/rrefsqlj81859.html Section on "adding constraints".

EDIT: This was the only thing that worked on the fiddle I tried:

ALTER TABLE table7
ADD (
      CONSTRAINT pk1 PRIMARY KEY (column1),
      CONSTRAINT fk1 Foreign Key (column2) REFERENCES Table1 (column2),
      CONSTRAINT fk2 Foreign Key (column3) REFERENCES Service (column3)
    )

Here's the fiddle: http://sqlfiddle.com/#!4/9d2a3

다른 팁

Check this out:

ALTER TABLE table7
ADD pk1 PRIMARY KEY(column1),
ADD fk1 FOREIGN KEY(column2) REFERENCES Table1(column2),
ADD fk2 FOREIGN KEY(column3) REFERENCES Service(column3)

See syntax and examples:

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/alter-table.html

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/alter-table-examples.html

ALTER TABLE table7 ADD ( CONSTRAINT pk1 PRIMARY KEY (column1), CONSTRAINT fk1 Foreign Key (column2) REFERENCES Table1 (column2), CONSTRAINT fk2 Foreign Key (column3) REFERENCES Service (column3) )

it works for me .Thanks

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top