Sobhan
Sobhan

Reputation: 816

Count the total number of databases

I am working in SQL server having a large number of databases. I want to count the number of databases. Is there any query to count?

Upvotes: 20

Views: 54146

Answers (6)

user3844864
user3844864

Reputation: 57

SELECT COUNT(*) FROM sys.databases where database_id not in ( 1,2,3,4 ).. excluding system database

Upvotes: 2

yogi
yogi

Reputation: 19591

SELECT * FROM sys.databases 

OR

SELECT COUNT(*) FROM sys.databases

Upvotes: 26

Sandy
Sandy

Reputation: 2449

If you only want to know the count, check this-

select COUNT(*) from sys.databases

check select * from sysdatabases for 2000 and 2005 server

Upvotes: 1

NetStarter
NetStarter

Reputation: 3225

SELECT count(1) FROM sys.databases

this is what you can have for counting the number of database check this link for more info

Upvotes: 1

mn.
mn.

Reputation: 846

try select COUNT(*) from sysdatabases or select COUNT(*) from sys.databases

edited from source: http://www.sqlservercentral.com/Forums/Topic401516-463-1.aspx#bm816566

Upvotes: 2

Sachin
Sachin

Reputation: 40970

You can try this

SELECT Count(*) as DatabaseCount FROM master..sysdatabases

or

SELECT count(*) as DatabaseCount FROM master.sys.databases

Upvotes: 2

Related Questions