Reputation: 816
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
Reputation: 57
SELECT COUNT(*) FROM sys.databases where database_id not in ( 1,2,3,4 ).. excluding system database
Upvotes: 2
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
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
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
Reputation: 40970
You can try this
SELECT Count(*) as DatabaseCount FROM master..sysdatabases
or
SELECT count(*) as DatabaseCount FROM master.sys.databases
Upvotes: 2