变量代替表名问题 set identity_insert 表名 on
declare @tablenaem varchar(100)
set @tablename='test1'
set identity_insert @tablename on
执行时报错
------解决方案--------------------
DECLARE @sql NVARCHAR(4000)
DELCARE @tablename varchar(100)
SET @sql='SET IDENTITY_INSERT '+@TABLENAME +' ON'
EXEC sp_executesql @sql
------解决方案--------------------declare @tablenaem varchar(100)
set @tablename='test1'
exec ('set identity_insert' + @tablename + 'on')