What is the difference between Primary Key and unique key constraint?

前端 未结 5 1157
我寻月下人不归
我寻月下人不归 2020-12-16 12:05

What is the difference between Primary key And unique Key constraint?

What\'s the use of it??

5条回答
  •  时光说笑
    2020-12-16 12:23

    Primary key:

    1. Primary key is nothing but it uniquely identifies each row in a table.

    2. Primary key does not allow duplicate values, nor NULL.

    3. Primary key by default is a clustered index.

    4. A table can have only one primary key.

    Unique Key:

    1. Unique key is nothing but it uniquely identifies each row in a table.

    2. Unique key does not allow duplicate values, but it allows (at most one) NULL.

    3. Unique key by default is a non-clustered index.

    This is a fruit full link to understand the Primary Key Database Keys. Keep in mind we have only one clustered index in a table [Talking about SQL Server 2005]. Now if we want to add another unique column then we will use Unique Key column, because Unique Key column can be added more than one.

提交回复
热议问题