Query all user tables with auto-incrementing columns in the database.

Source: Internet
Author: User

Most of the time, we need to find all the database tables with auto-incrementing columns in the database. When there are many database tables, it is too troublesome to query them by ourselves,

So I wrote a script to help us find and print the database table name. The Code is as follows:

---- Query all tables with auto-incremental IDs in the database
Declare curtablename cursor local
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, 'tablehasauth') = 1
And upper (name) = upper (@ table_name)
)
Print @ table_name
End
End

Close curtablename
Deallocate curtablename

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.