.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

Doubts in primary key and foreign key concepts.

Posted By: sridar1     Posted Date: April 17, 2011    Points:5   Category :Sql Server
Hai,

I have some doubts in sql for creating primary key and foreign key concepts.plz help me.Below table which is primary key and which is foreign key.

create table LOANFD_FIXED_DEPOSIT_TB
(
DATE_CREATION DATETIME,
FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM VARCHAR(10),
FD_NUM VARCHAR(10),
FD_AMNT MONEY,
MATURITY_DATE DATETIME,
RATE_OF_INTEREST NUMERIC,
NOMINEE VARCHAR(10),
RELATIONSHIP VARCHAR(10),
REQUEST_LETTER TEXT,
STATUS VARCHAR(10),
PRIMARY KEY(FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM,FD_NUM)
)

Responses
Author: shankey             
Posted Date: April 18, 2011     Points: 20   

hi,

I think in above scenario

FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM will be FK
FD_NUM will be PK

Please reply if any confusion and confirm that we are on same track.

Shankey
Author: sridar1             
Posted Date: April 18, 2011     Points: 20   

But in the last line

"PRIMARY KEY(FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM,FD_NUM)" the word primary key which means to which one either FD_NUM or FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM

Author: shankey             
Posted Date: April 18, 2011     Points: 20   

hi

PRIMARY KEY(FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM,FD_NUM)

above line defines composite key, i.e. the combination of FK_FIXED_DEPOSIT_CUST_DETAILS_ACC_NUM,FD_NUM uniquely identify a row.

So where the doubt is, i m not clear about you doubt.

Please reply

Thanks,

Shankey
Author: Narayanan             
Posted Date: July 13, 2011     Points: 20   

Hi,
I think,
FK -- Foreign Key
PK -- Primary Key
Regards,
Lakshmi Narayanan.S

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
Author: Narayanan             
Posted Date: July 13, 2011     Points: 20   

Hi,
I think,
FK -- Foreign Key
PK -- Primary Key
Regards,
Lakshmi Narayanan.S

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
Author: sriram             
Posted Date: October 27, 2011     Points: 20   

u r create a table structre in incorrect u r creating composite key.

Primary key: Each Table can have only one primary key,primary key Restrict Duplicate values and null values

unique key: Restrict Duplicate values and allow one null values.

Foreign Key:what ever values insert in primary key column table those values on u can able to insert child table.

primary table:

create table emp(empid int constraint pk_empid primary key(empid),empname varchar(90))

childTable:

create table empsalary(empid int references emp(empid),empstate varchar(90))

hope this wll help ;;
let me know any Questions

Regards

Sriram.R




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend