5
When creating a table in Mysql I used to create fields CONSTRAINT FOREIGN KEY
how are you following to create the foreign key:
CREATE TABLE socio
(
id_socio INTEGER NOT NULL,
nome VARCHAR(256) NOT NULL,
cpf VARCHAR(11) NOT NULL,
email VARCHAR(256),
id_situacao INTEGER,
CONSTRAINT pk_id_socio PRIMARY KEY (id_socio),
CONSTRAINT un_socio_cpf UNIQUE (cpf),
CONSTRAINT socio_id_situacao_fk_ref FOREIGN KEY (id_situacao) REFERENCES situacao (id_situacao)
);
What’s the difference when creating tables, use only the FOREIGN KEY
or the FOREIGN KEY
with CONSTRAINT
to create foreign keys?
I believe the difference is that when you use
CONSTRAINT <nome> FOREIGN KEY ...
you are explicitly declaring to Constraint, that is, naming it. Already in the other situation, the database itself is in charge of appointing the Constraint. Take a look here.– pauloimon
So there is no correct difference? Only that in one case you give a name and in the other the back chooses
– Wííl TR
Exact! In terms of functionality there is no difference.
– pauloimon