New course! Every coder should learn Generative AI!
Try a free lesson0
what is primary and foreign key?
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.
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.