Welcome Guest. Sign in or Signup

2 Answers

Primary Key vs Foreign Key

Asked by: 3212 views SQL

What are Primary Keys? How would you determine the candidates for a Primary Key? How are primary Keys different from Foreign Keys?

Related Questions

2 Answers



  1. muneendra vemula on Feb 24, 2014 Reply

    Primary key does not allow duplicates.
    And Foreign key references the primary key field.

    0 Votes Thumb up 0 Votes Thumb down 0 Votes



  2. lilsam on Jul 14, 2016 Reply

    The concept of Primary and Foreign key relates to a common identity which binds different record data.

    It creates a Parent-Child relationship between different record data.
    Consider EMPLOYEE record which has EMPLID as PK and record DEPARTMENT which has DEPTID as PK as well as an additional key EMPLID which is also a key field.

    Suppose, we want to find out all the EMPLOYEES who are assigned to a DEPARTMENT, then we can make use of the EMPLID field present in both records. So, here the EMPLID from EMPLOYEE record acts a PK which will be joined to EMPLID of DEPARTMENT record which acts as a FK.

    SELECT A.EMPLID,B.DEPTID
    FROM EMPLOYEE A, DEPARTMENT B
    WHERE A.EMPLID = B.EMPLID

    Hope this is meaningful!

    +1 Votes Thumb up 0 Votes Thumb down 0 Votes


Answer Question