Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error table variable

Tags:

t-sql

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.

like image 929
cs0815 Avatar asked Mar 29 '26 00:03

cs0815


1 Answers

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
like image 189
gbn Avatar answered Apr 01 '26 12:04

gbn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!