SQL Server query to find all current database names

前端 未结 8 507
傲寒
傲寒 2020-12-03 09:34

I need a SQL query to find the names of existing databases.

相关标签:
8条回答
  • 2020-12-03 09:56

    For people where "sys.databases" does not work, You can use this aswell;

    SELECT DISTINCT TABLE_SCHEMA from INFORMATION_SCHEMA.COLUMNS
    
    0 讨论(0)
  • 2020-12-03 09:58

    Another to add to the mix:

    EXEC sp_databases
    
    0 讨论(0)
  • 2020-12-03 10:08

    Here is a query for showing all databases in one Sql engine

    Select * from Sys.Databases
    
    0 讨论(0)
  • 2020-12-03 10:10

    I don't recommend this method... but if you want to go wacky and strange:

    EXEC sp_MSForEachDB 'SELECT ''?'' AS DatabaseName'
    

    or

    EXEC sp_MSForEachDB 'Print ''?'''
    
    0 讨论(0)
  • 2020-12-03 10:11
    SELECT name  
    FROM sys.databases
    

    You'll only see the databases you have permission to see.

    0 讨论(0)
  • 2020-12-03 10:13
    SELECT datname FROM pg_database WHERE datistemplate = false
    

    #for postgres

    0 讨论(0)
提交回复
热议问题