Primary Key vs. Foreign Key vs. Unique Key

I know this is a very basic concept and I predominantly understand the purpose of a Primary Key and a Foreign Key. But as I've been learning the concept of a Unique Key came up and I was unable to find a resource that gives me a clear understanding of the purpose of a Unique Key. I would love it if someone co explain the difference while comparing it to Primary and Foreign Keys potentially with some examples if applicable.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    primary key : evry row must have unique value. so we can identify row easily. so nulls cant be accepted and duplicate values also not allowed. 

    Foreign Key : easily represents the relation b/w tables. 

    Unique Key: mainly values has unique but null values allowed and duplicate values not allowed. eg: bank ac number or debit card numbers or vehicle number plates etc.. 

Reply
  • 0
    Certified Senior Developer

    primary key : evry row must have unique value. so we can identify row easily. so nulls cant be accepted and duplicate values also not allowed. 

    Foreign Key : easily represents the relation b/w tables. 

    Unique Key: mainly values has unique but null values allowed and duplicate values not allowed. eg: bank ac number or debit card numbers or vehicle number plates etc.. 

Children
No Data