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
Hi shsingh1
Primary Key: A primary key uniquely identifies each record in a table. Each value in the primary key column must be unique. primary key cannot contain NULL values. Every record must have a value for the primary key. The primary key is defined within a single table.
Foreign Key: A foreign key is a column or set of columns in one table that refers to the primary key in another table. It establishes a relationship between the two tables. Foreign keys can contain NULL values, depending on the design of the database. The foreign key is defined in a child table and references the primary key of a parent table.