Skip to main content

Posts

Showing posts with the label The Crazy Programmer Difference between Primary Key and Unique Key Difference between Primary Key and Unique Key The Crazy Programmer

Difference between Primary Key and Unique Key Vijay Sinha The Crazy Programmer

In this article we look into the difference between Primary Key and Unique Key Constraints. We will see the description of both along with how to define a schema and create attributes in a table with these constraints. Primary Key A Primary Key is a key attribute or a column which is used to uniquely identify a row (tuple) in a table (relation). It maintains the integrity constraints of a table. A table can have only one primary key attribute. The data of primary key must be unique. Hence, no duplicate values are valid. Also, no NULL (empty) values are allowed during insertion as it violates the integrity constraint. The database automatically creates a Clustered Index over primary key which orders data on the basis of primary key. We define a Primary Key Attribute as follows: Column_Name DataType PRIMARY KEY Unique Key A Unique Key is a constraint or key attribute which also uniquely identifies a row in a table. It’s purpose is somewhat same as primary key. It differs in ways