I have a SQL Server 2012 database called MyDatabase
. How can I find how many tables are in the database?
I'm assuming the format of the query would be something like the following, but I don't know what to replace database_tables
with:
USE MyDatabase
SELECT COUNT(*)
FROM [database_tables]
This question is related to
sql-server
tsql
count
sql-server-2012
database-table
Try this:
SELECT Count(*)
FROM <DATABASE_NAME>.INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
USE MyDatabase
SELECT Count(*)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';
to get table counts
SELECT COUNT(*)
FROM information_schema.tables
WHERE table_schema = 'dbName';
this also works
USE databasename;
SHOW TABLES;
SELECT FOUND_ROWS();
Source: Stackoverflow.com