Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
671 views
in Technique[技术] by (71.8m points)

tsql - syntax error table variable

This is the code:

declare @Ids table ( Id int identity(1,1));

SET IDENTITY_INSERT @Ids ON;

and I get:

Incorrect syntax near '@Ids'

I cannot see what's wrong. Any ideas? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't use SET IDENTITY_INSERT on table variables

This works

CREATE TABLE Ids ( Id int identity(1,1))
SET IDENTITY_INSERT Ids ON

and this

CREATE TABLE #Ids ( Id int identity(1,1))
SET IDENTITY_INSERT #Ids ON

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...