Monday, May 24, 2021

Count the Number of Tables in a Database in SQL Server

 This query will return the number of tables in the specified database.

Output is same for all the methods below.

Method 1:

USE AdventureWorks2017
GO

SELECT COUNT(*) from INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'

Following is another way this can be done for all user tables.

Method 2:

USE AdventureWorks2017
GO

SELECT COUNT(*) FROM sys.tables

Output:

71

Related Article:

No comments:

Post a Comment