ORA-00907: right parenthesis not found - Help

Asked

Viewed 300 times

1

I am trying to create the following table in SQL

create table Compra 
(
    CodCompra number(3) primary key, 
    DataCompra date, 
    DataEntrega date,
    Fornecedor foreign key Fornecedor REFERENCES (codfornecedor)Fornecedor
)

ORA-00907: right parenthesis not found

When removing the "Fornecedor foreign key Fornecedor REFERENCES (codfornecedor)Fornecedor" table is created normally. And when giving the command

alter table Compra
add foreign key (Fornecedor) references Fornecedor (Fornecedor)

It features Fornecer as an invalid identifier.

Obs.: The table has been created FORNECEDOR primary key CodFornecedor.

1 answer

2

Make a small change in this section

Fornecedor foreign key Fornecedor REFERENCES (codfornecedor)Fornecedor

Change to that

FornecedorID int FOREIGN KEY REFERENCES Fornecedor(codfornecedor)

Supplier will be a column in the table Buying, so change your name to Supplier, is a database pattern. Another thing that was missing was to say the field type, in case int and finally, enter the name of the table that is being referenced before the field, with this I believe your command will be executed

The complete command would be this

CREATE TABLE Compra (
  CodCompra number(3) PRIMARY KEY, 
  DataCompra date, 
  DataEntrega date, 
  FornecedorID int FOREIGN KEY REFERENCES Fornecedor(codfornecedor) 
);

Check if the column codsupplier is written like this in your table of Supplier

  • It worked out! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.