How can I make a column AUTOINC in TSQL / SQL Server Express?

The Server Explorer Table creation facility automatically adds an Id column to each Table you create:

enter image description here

But I noticed that, although it is indeed set as a PRIMARY KEY, it does not specify that it is an AutoInc column.

So I added that directly to the T-SQL tab, but that is considered a syntax error:

enter image description here

Is it already an auto-inc, and I don't need to specify it as such, or if I do need to, what am I doing wrong?

Upvotes: 0

Views: 195

Answers (1)

MLeblanc
MLeblanc

Reputation: 1909

In SQL Server, it's not an AUTO_INCREMENT, it's an identity:

CREATE TABLE dbo.Genres 
(
   [GenreId] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
   [Genre]   VARCHAR(20) NULL
);

https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver15

Upvotes: 7

Related Questions