When creating a table, just set it as an identifier and this will give you the value of auto increment id. An example is below.
CREATE TABLE MyTable
(
MyId INT IDENTITY(1,1) PRIMARY KEY,
MyColumn VARCHAR(500)
)
IDENTITY(1,1) sets the ID field to start at 1 and increments by one for each new record.
source
share