Results 1 to 8 of 8

Thread: Primary key & foreign key

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Primary key & foreign key

    Plz tell me with example the difference between Primary key,foreign key,unique key


  2. #2
    Expert Member
    Join Date
    Sep 2007
    Answers
    697

    Re: Primary key & foreign key

    Unique Key prohibits multiple rows from having the same value in the same column or combination of columns . But it allows null values.

    Primary key is a combination of UNIQUE KEY and NOT NULL. It will not allow duplicate values and null values.

    Foreign key ensures conformity between two tables. If a column is defined as foreign key it can contain only values from a parent table's primary key or a unique key.

    For examples follow the link


  3. #3
    Moderator
    Join Date
    Jun 2007
    Answers
    2,074

    Re: Primary key & foreign key

    Primary key---------enforces both uniqueness and not null(no duplicate and no null in the column)
    foreign key----------maintains referential integrity(child record refers to parent record)
    unique key----------maintains uniqueness of data in the column(no duplicate records)


  4. #4
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: Primary key & foreign key

    primary key not accept null value & it is related with unique table while foreign
    key is related with more than one table with one simillar coloumn.


  5. #5
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: Primary key & foreign key

    Quote Originally Posted by amitdba08 View Post
    Plz tell me with example the difference between Primary key,foreign key,unique key

    primary key is key to identify uniqe record,is not null,unique,dont allow duplicate

    foreign kay is key which act as primary key in one table & foreign key in another table
    it is reference bet two table

    unique key is same as primary key


  6. #6
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: Primary key & foreign key

    just to add here unique key can contain null value, while primary key can not contain null value.


  7. #7
    Junior Member
    Join Date
    Jun 2008
    Answers
    2

    Re: Primary key & foreign key

    primary key is combination of both unique and notnull keys.
    unique key is a key which is not accept any duplication.
    foriegn key is a key which is act as a primary key to some other table.


  8. #8

    Thumbs up Re: Primary key & foreign key

    Set of fields in database taken collectively to identify any row uniquely is called Candidate key...
    So Database has more than 1 Candidate key...

    Primary key is the Candidate key choosen by the Database Designer...

    Unique Key is the constraint that is used to insert unique value in the field of the database...


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact