您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

查找数据库中所有有自增列的用户表

2025/6/25 20:40:24发布12次查看
查找数据库中所有有自增列的用户表 很多时候我们需要查找数据库中的所有的有自增列的数据库表,数据库表多的时候,自己去查太麻烦了, 所以我写了段脚本帮我们查找并打印出数据库表名,代码如下所示: ----查询数据库中所有有自增id的表 declare curtablenam
查找数据库中所有有自增列的用户表
很多时候我们需要查找数据库中的所有的有自增列的数据库表,数据库表多的时候,自己去查太麻烦了,
所以我写了段脚本帮我们查找并打印出数据库表名,代码如下所示:
----查询数据库中所有有自增id的表
declare curtablename cursor local for
select name from sys.objects where type='u'
open curtablename 
declare @table_name varchar(100)
begin
fetch next from curtablename into @table_name
while @@fetch_status=0
begin
fetch next from curtablename into @table_name
if exists(select top 1 1 from sysobjects
    where objectproperty(id, 'tablehasidentity') = 1
      and upper(name) = upper(@table_name)
  )
 print @table_name
end
end
close curtablename
deallocate curtablename
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product