What is the difference between primary and foreign key? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between primary and foreign key?

I still find it confusing and I need more questions to further explicate its difference

16th Jun 2017, 12:58 PM
Dani Manalang
Dani Manalang - avatar
6 Answers
+ 14
Primary key is unique identifier in a table while​ foreign key is a field in one table which is primary key in other table. Primary key can't accept null values while foreign key can accept multiple null values. Only one primary key is possible for a table but multiple foreign keys are possible which link multiple tables to parent table Edit: This might help https://www.essentialsql.com/what-is-the-difference-between-a-primary-key-and-a-foreign-key/
16th Jun 2017, 1:16 PM
Frost
Frost - avatar
+ 12
I guess for each table.. there can be one primary key
16th Jun 2017, 1:18 PM
Frost
Frost - avatar
+ 2
only one primary in one database or only one primary in each table? :D
16th Jun 2017, 1:18 PM
Dani Manalang
Dani Manalang - avatar
+ 2
Thank you it somewhat enlightens me! @frost
16th Jun 2017, 1:25 PM
Dani Manalang
Dani Manalang - avatar
+ 1
for each table there is only one primary key and it cannot be null.
16th Jun 2017, 2:59 PM
pooja shedutkar
pooja shedutkar - avatar
0
Primary key is unique and not null but foreign key is may or may not be unique and nulls accepted and also duplicate rows allowed
17th Jun 2017, 5:56 PM
Venkateshwarlu Ande
Venkateshwarlu Ande - avatar