1
I have the following tables :
Create table OS(
nro_os number(4),
data_os date ,
hora_os number(4)
);
Create table cliente(
cod_cliente number(4),
nome_cliente varchar(12),
endereco_cliente varchar(20),
telefone_cliente number(11)
);
And I have the following ALTER TABLE :
Alter table OS
add (constraint cliente_cod_cliente_fk foreign key (cod_cliente) references cliente (cod_cliente));
Only when I run the query, it returns the error :
ORA-00904: "COD-CLIENT": invalid identifier
How can I add foreign key with ALTER TABLE correctly ?
Hello, can I add the Foreign key without first having to add the attribute to the table ? Without having to put the cod_client in the OS, and simply add with the alter table ?
– Monteiro
You can do everything in one
ALTER TABLE
, where it creates the attribute and the Constraint at the same time, I will include in the answer.– Zulian
Thank you for the most complete answer, +1 and correct answer.
– Monteiro