How can I view the List of databases that available in a SQL server instance via query?

There are many ways to see all the databases, here i’ve listed 3 types

1. master..sysdatabases – system table added as view for backward compatabilty

2. sys.databases – view available in master & user databases. minimum permission is enough to view the output

3. sp_databases – Inbuilt stored Procedure, to fetch DB lists.
Requires CREATE DATABASE, or ALTER ANY DATABASE, or VIEW ANY DEFINITION permission, and must have access permission to the database. Cannot be denied VIEW ANY DEFINITION permission. everyone can not access this SP, if you dont have permission, then you will see blank rows.

USE master;
GO

SELECT Name FROM master..sysdatabases

SELECT * from sys.databases

EXEC sp_databases;

Sample Output: 

Categories: Uncategorized

Related Posts

Uncategorized

SQL – Get Current, Previous & Next Quarter

The below SQL script will help you to find, First & Last Date of the Current/Previous/Next Quarter based on the current Date.