how many databases present in the sqlserver

  • HI,

    Please send T-Sql query to find total number of database present in the server.

    Ex: No.of Database :50

    Thanks in advance

  • SELECT COUNT(name) FROM sys.databases

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • another (not so efficient) method:

    SELECT top 1 database_id as DB_COUNT

    FROM sys.databases

    order by database_id DESC

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Hi,

    Select count (*) from sys.databases

    Thanks,

    Nagesh

  • Thank you very much for your replies but it is not working in sql 2000

    pls provide solution to work all the versions of sql

    Thanks in advance

  • In 2000 simply use

    Select count (*) from sysdatabases --without the . between sys and databases

    and not

    Select count (*) from sys.databases

    Next time dont put sql 2000 questions under the 2008 section.

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Hi,

    You’re in the 2008 Forums, but you need for 2000!!!

    Select count (*) from sys.databases -- above 2000 version

    select count (*) from master..sysdatabases -- in 2000

  • sivark1 (1/21/2010)


    Thank you very much for your replies but it is not working in sql 2000

    Hmm, this IS a SQL 2008 forum that you posted in.....;-)

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply