ORA-00907: right parenthesis not found - Help

1

I'm 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 you remove " Fornecedor foreign key Fornecedor REFERENCES (codfornecedor)Fornecedor " the table is created normally. And giving the command

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

It characterizes Fornecer as an invalid identifier.

Note : The FORNECEDOR table with the primary key CodFornecedor has already been created.

    
asked by anonymous 08.09.2018 / 00:29

1 answer

2

Make a little change in this section

Fornecedor foreign key Fornecedor REFERENCES (codfornecedor)Fornecedor

Change to this

FornecedorID int FOREIGN KEY REFERENCES Fornecedor(codfornecedor)

Vendor will be a column in the Buy table, so rename it SupplierID is a database default. Another thing that was missing was to say the type of the field in the int case and finally, enter the name of the table that is being referenced before the field, so I think your command will be executed

The complete command would be

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

Make sure that the supplier column is spelled as such in your Vendor table     

08.09.2018 / 02:53