Query the number of user tables in the SQL Server database

Source: Internet
Author: User

During Development today, I encountered the problem of counting the number of database tables in SQL Server 2005. So I wrote the SQL statement myself: Select count (1) From sysobjects where xtype = 'u'. Once executed, I found that the number of tables obtained by the query is one more than the actual number of user tables. A closer look shows that there are more data entries in the result.

The figure is as follows:

Sysdiagrams is not a user table, but a relational diagram of the database. However, I did not have a relational database. I accidentally clicked under the current database when operating SSMs.

As shown in the following figure:

If yes is selected, the result obtained from the preceding query is displayed.

The answer to this question is revealed.

So I changed the SQL query statement to avoid this situation.

Only count the number of user tables:

Select count (1) From sysobjects where xtype = 'U' and [name] Not in ('sysdiagrams ')

 

 

 

 

 

 

 

Related Article

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.