Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created December 3, 2019 16:18
Show Gist options
  • Save wbhinton/8cc98318f581fcef3727a3d5e13ed325 to your computer and use it in GitHub Desktop.
Save wbhinton/8cc98318f581fcef3727a3d5e13ed325 to your computer and use it in GitHub Desktop.
List All Databases on a server (MSSQL)
EXEC sp_helpdb;
--OR
EXEC sp_Databases;
--OR
SELECT @@SERVERNAME AS Server ,
name AS DBName ,
recovery_model_Desc AS RecoveryModel ,
Compatibility_level AS CompatiblityLevel ,
create_date ,
state_desc
FROM sys.databases
ORDER BY Name;
--OR
SELECT @@SERVERNAME AS Server ,
d.name AS DBName ,
create_date ,
compatibility_level ,
m.physical_name AS FileName
FROM sys.databases d
JOIN sys.master_files m ON d.database_id = m.database_id
WHERE m.[type] = 0
-- data files only
ORDER BY d.name;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment