When inserting a record into a table, I want SQL Server to generate a number automatically for the Primary Key. (e.g. OrderID is 1, 2, 3 and so on) How to do it?
(This behavior is similar to the "Auto-number" in Microsoft Access)
Essential steps:
- Go to MS SQL Server > SQL Server Management Studio Express
- Right Click the table (e.g. Orders) > Design table.
- The primary key column (e.g. OrderID) must be defined using the decimal, int, numeric, smallint, bigint, or tinyint data type.
- Select the primary key and set the "Identify specification > IsIdentity" to yes.
Refer to the following snapshot. Click the snapshot to enlarge it.
Keywords:
Database Server
Microsoft SQL Server FAQ, MS SQL Server FAQ
Information Technology, SQL
|
0 Comments