Guys....help me. what is a primary key and foreign key and show me an example about it.... !! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Guys....help me. what is a primary key and foreign key and show me an example about it.... !!

Fk and Pk

6th Dec 2016, 1:19 PM
Agustav Basis
Agustav Basis - avatar
4 Answers
+ 4
A Foreign key is a column in one table which is the primary key on another table. Foreign key and a Primary key is used to define relationship between two tables in relational database. A foreign key can be empty and it does not give you auto increment because it is primary key from other table and if you don't know what is primary key at specific location. But primary key cannot be empty and it can auto increment like id. Hope it helps, If you want more information please reply
6th Dec 2016, 1:47 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
can you show me an example code of primary key or foreign key please ??
6th Dec 2016, 3:38 PM
Agustav Basis
Agustav Basis - avatar
0
Primary key ina qunique identifier while foreign key is not. A primary key can be a foreign key but the vice versa is not possible.
7th Dec 2016, 7:43 AM
Abhishek Shekhar
0
e.g.: customer table customerID can be a primary key if it is unique identifier for that row For instance for customer table: customerID = 1, name = ben, age = 25, email = ben@email.com customerID = 2, name = jon, age = 21, email = jon@email.com customerID = 3, name = ben, age = 21, email = ben123@email.com There can be duplicate name and age as they are not a primary key. email can be a foreign key in customer table that is used to link to account table. Foreign key is a key that is used to link to another table e.g.: account table email = ben@email.com, password = ben111 email = jon@email.com, password = jonn123 email = ben123@email.com, password = ben1234 In this example, foreign key have to be unique but it is not necessary for foreign key to be unique.
7th Dec 2016, 8:28 AM
lowshuen