Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
How to use Primary Key and Foreign Key in SQl?.Give Solution with Example???

Regards
Balamurugasn
Posted

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search using your question as the search term gave over 1.5 million hits: Google : How to use Primary Key and Foreign Key in SQl[^]
The first hit is W3Schools: http://www.w3schools.com/sql/sql_foreignkey.asp[^] with a good explanation and example.

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 
Comments
Shahriar Iqbal Chowdhury/Galib 31-Oct-12 17:24pm    
+5 strongly agree. Also i think providing straight answer for this kinda question effect the learning curve of the beginners.
Assume there are two tables

Create table empmaster
(
empid Int identity(1,1) primary key,
Empname varchar (20),
Empaddress varchar(50),
EMpDoB datetime
)

create table empjob
(
jobid int not null,
empid int not null,
jobdesc varchar(40),
FOREIGN KEY (empid) REFERENCES empmaster(empid)
)

here we are refering the primary key and foreign key relationship to get the detail records for particular employee with jobdesc.
Hope its help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900