what is primary and foreign key? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is primary and foreign key?

11th Sep 2016, 7:28 AM
Sudarshan Kuppalli
Sudarshan Kuppalli - avatar
2 Answers
+ 3
A primary key is a unique identifier for a column in a table can not be null and does not allow repeated values in that column. A foreign key is a reference to a key in another table, establishes the relationship between two tables. For example, we have these two tables: person (id, name, surname, age); id is a primary key. car (registration, make, model, id_person); id_person is a foreign key, refers to the id key car owner. I hope it helps you.
11th Sep 2016, 7:47 AM
Fran Lopez
Fran Lopez - avatar
0
PRIMARY KEY - 1)it's unique . this helps in joining two different tables in a database so that no redundant data is obtained. Basically the whole column is supposed to have distinct/unique data 2) It cannot contain the null values ___________________________________________ FOREIGN KEY- 1)It's used as reference of Primary key. That is when you create a join in order to match data you need a corresponding foreign key.It can contain any number of duplications. 2)It can contain the null values.
11th Sep 2016, 10:47 AM
Siddhant Singh
Siddhant Singh - avatar