I’m trying to create a table variable with primary key. What is the difference between these two statements? Why the first one does not work?
--This does not work
declare @tabvar table (
rowid int identity(1, 1) not null,
var1 int null,
constraint PK_tabvar_rowid primary key clustered (rowid)
)
--This works
declare @tabvar1 table (
rowid int identity(1, 1) not null primary key clustered,
var1 int null
)
Looks like this behavior is well documented in BOL. Look at the syntax definitions for DECLARE TABLE Variable vs CREATE TABLE.