What is difference between foreign key and referen

2019-02-02 21:48发布

I am very confused about those two terms. Are they the same or different?

Some books and people say they are the same and others say they are different.

I tried but couldn't find a conclusive answer.

8条回答
祖国的老花朵
2楼-- · 2019-02-02 22:44

I am supposing that you are talking about using the REFERENCES where the FOREIGN KEY keyword is not used, eg.

author_id INTEGER REFERENCES author(id)

... instead of ...

author_id INTEGER,
FOREIGN KEY(author_id) REFERENCES author(id)

The answer is, that it is simply shorthand syntax for the same thing. The main concern when altering between the two should be readability.

查看更多
混吃等死
3楼-- · 2019-02-02 22:45

The only and most important difference between the two keywords 'FOREIGN KEY" and "REFERENCES" keywords is though both of them make the data to be child data of the parent table, the "FOREIGN KEY" is used to create a table level constraint whereas REFERENCES keyword can be used to create column level constraint only. Column level constraints can be created only while creating the table only. But table level constraints can be added using ALTER TABLE command.

查看更多
登录 后发表回答