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 ')