Comparison of PRIMARY Key and identity (1,1)

Source: Internet
Author: User

PRIMARY KEY Constraint


A table often has a combination of columns or columns whose values uniquely identify each row in the table.

One or more of these columns is called the primary key of a table, through which you can enforce the entity integrity of a table.

You can create a primary key by defining a PRIMARY key constraint when you create or change a table.

A table can have only one PRIMARY key constraint, and a column in a PRIMARY KEY constraint cannot accept null values.

Because the PRIMARY KEY constraint ensures unique data, it is often used to define identity columns.

If the PRIMARY key constraint is defined on more than one column, the values in one column can be duplicated, but the values of all the columns in the PRIMARY KEY constraint definition must be unique.




IDENTITY (properties) (Transact-SQL)


Create an identity column in the table.
This property is used with the CREATE table and ALTER table Transact-SQL statements.

The identity property differs from the SQL-DMO identity property, which provides the row identity property of the column.

Scope of application: SQL Server (SQL Server 2008 to current version).


Grammar


IDENTITY [(seed, increment)]
Parameters
Seed
The value used by the first row loaded into the table.


Increment
The increment value that is added to the identity value of the previous loaded row.

Both the seed and increment must be specified, or neither is specified. If neither is specified, the default value (1,1) is taken.


Summarized as follows:

Primary key is a primary key, typically used in a column, whose value cannot be null and has a unique value. can also be used with multiple columns, and the combined values of multiple columns are unique.

Identity is the attribute, and the self-added column. The field of the IDENTITY cannot be assigned by default in the INSERT statement.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.