Let's take a look at the table below: Think about how we can add data to this table more easily in database SQL Server.
Careful observation of this table we are not difficult to find that the ID field of this column of data recharge is a rule to follow, it is an increase in the number of columns, to the data table to add such data is there a simple way?
This refers to the problem with the SQL Server identity column. I have some information to make a summary, here and you share with the exchange.
(1) Definition of the identity column
An identity column, often referred to as an "identity field" or "Automatic growth field," is the identity of a row that distinguishes other records, and is uniquely able to retrieve that row record.
Note: You can have only one identity column in a table (the superscript segment), usually by setting the primary key to an identity column.
(2) How to set a field to an identity column?
Let me take SQLServer2008 as an example to look at its setup steps:
such as: Right-click-Table Person3, left-click-Design property, and then select the field you want to set as the identity column, in the identity specification, set the field's identity to Yes, and finally close the window and save it.
As you can see from the "Identity specification" in the figure above, there is also a "identity seed" and "identity increment" in the identity column, primarily to avoid the occurrence of duplicate values and to facilitate querying.
1. Identifies the number of seeds to begin with and defaults to 1.
2. The identity increment (also known as the growth Seed) is the value added to each additional piece of data, and the default is 1.
3. The identity column does not allow inserting the value, is automatically gives the value, the force gives the error.
Identity (1,1) then the column identifies the seed as 1, and the growth seed is also 1. The first parameter is the seeded seed, and the second parameter is the growth seed.
Note: Before you set up an identity column, you can find-' options ' in the options-in the option-remove ' √ ' to prevent saving requests for the rebuild of the table, or SQL Server will not be able to modify the identity column of the table.
(3) To set the benefits of an identity column
The identity column is automatically incremented, starting at the seed, incrementing by increments, and set by the increment bit itself. For example: The seed is 1, the growth rate is 1, then the value of the identity column is: 1, 2, 3, 4, 5 ... by analogy. So when you write the INSERT statement, you don't have to write the value of the identity column.
In other words: the identity column to achieve the field of self increase, to solve the problem of concurrency, without the developer control, SQL Server automatically assigns the value of the identity column, if two people at the same time to insert data into the database, will produce a unique automatic increase for identification.