MS SQL Helpful Statistics Queries

In this post you will find some method of return some helpful information for Microsoft SQL

Get a list of databases

The below query will return a list of none system databases on a Microsoft SQL Server;

SELECT name FROM master..sysdatabases WHERE dbid > 4

Or you can run the below to get a list of databases along with their size and remarks;

EXEC sp_databases

Get the number of tables

The below SQL snippet will return a count of the number of tables in a database.

Make sure to change the “use” statement to the required database name

USE YOUR_DATABASE_NAME
SELECT COUNT(*) from information_schema.tables
WHERE table_type = 'base table'

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.