读书人

有没有办法使identity的始量,可以用变

发布时间: 2012-01-16 23:36:51 作者: rapoo

有没有办法使identity的始量,可以用变量来替代?
declare @beginnum as int
set @beginnum = 88
select identity(int,@beginnum,1) as iden into #t1 from sysobjects
select * from #t1
drop table #t1

上面的是错误的,那么有没有办法使identity的始量,可以用变量来替代?

进一步说,有没有办法,可以使identity的始量和增量,可以用变量来替代?


[解决办法]
那只有用动态SQL实现。

declare @beginnum as int, @sql varchar(1000)

set @beginnum = 88

set @sql = 'select identity(int, ' + cast(@beginnum as varchar(100)) + ',1) as iden into #t1 from sysobjects select * from #t1 drop table #t1 '

print @sql

exec (@sql)


读书人网 >SQL Server

热点推荐