今天要统计一下数据库里所有表当前的最大id,一个一个查太麻烦了,就写了一个存储过程,方便今后继续使用。 create procedure [dbo].[get_tableid] as create table #tablespaceinfo --创建结果存储表 (nameinfo varchar(50) , max_idinfo int ) declare @ta
        		今天要统计一下数据库里所有表当前的最大id,一个一个查太麻烦了,就写了一个存储过程,方便今后继续使用。
create procedure [dbo].[get_tableid] as
create table  #tablespaceinfo                         --创建结果存储表 
              (nameinfo varchar(50) ,  
               max_idinfo int )
declare @tablename varchar(255)  --表名称 
declare @max_idinfo int
declare info_cursor cursor for  
select o.name   
from dbo.sysobjects o where objectproperty(o.id, n'istable') = 1  
     and o.name not like n'#%%'  order by o.name
open info_cursor
fetch next from info_cursor  
into @tablename
while @@fetch_status = 0 
begin 
if exists (select * from dbo.sysobjects where id = object_id(@tablename) and objectproperty(id, n'isusertable') = 1) 
begin
select  @max_idinfo=ident_current(@tablename)
insert #tablespaceinfo (nameinfo,max_idinfo) 
values (@tablename,@max_idinfo)
end
fetch next from info_cursor  
  into @tablename  
end
close info_cursor 
deallocate info_cursor
select * from #tablespaceinfo order by nameinfo desc
   
 
   