Reputation: 634
Is there any difference in declaring foreign keys on tables between this two options?
OPTION 1
create table Table1 (
name varchar(255),
id_fkey int references Table2 (id)
);
OPTION 2
create table Table1 (
name varchar(255),
id_fkey int,
foreign key (id_fkey) references Table2 (id)
);
Are both declarations of a proper foreign key
or do they have any difference?
Upvotes: 0
Views: 79
Reputation: 246598
These are two ways to do the same thing. The first syntax is called column constraint, the second table constraint.
The only real difference is that a foreign key over more than one column can only be written as a table constraint.
Upvotes: 1