Home > Database > Mysql Tutorial > 查找数据库中所有有自增列的用户表

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

WBOY
Release: 2016-06-07 14:58:26
Original
1514 people have browsed it

查找数据库中所有有自增列的用户表 很多时候我们需要查找数据库中的所有的有自增列的数据库表,数据库表多的时候,自己去查太麻烦了, 所以我写了段脚本帮我们查找并打印出数据库表名,代码如下所示: ----查询数据库中所有有自增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 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template