Are this foreign key instances the same?

user157629 :

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?

Laurenz Albe :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=346260&siteId=1