Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of databases from SQL Server

Tags:

sql-server

How can I get the list of available databases on a SQL Server instance? I'm planning to make a list of them in a combo box in VB.NET.

like image 567
sef Avatar asked Sep 29 '08 05:09

sef


People also ask

What is the query to list all the Databases?

To do that we will be using the below given commands: CREATE TABLE [database_name.] table_name ( pk_column data_type PRIMARY KEY, column_1 data_type NOT NULL, column_2 data_type, ..., table_constraints ); If we do not mention the name of the database then the default USE database is selected for the creation of tables.

How do I get a list of Databases and sizes in SQL Server?

If you need to check a single database, you can quickly find the SQL Server database sizein SQL Server Management Studio (SSMS): Right-click the database and then click Reports -> Standard Reports -> Disk Usage. Alternatively, you can use stored procedures like exec sp_spaceused to get database size.


1 Answers

Execute:

SELECT name FROM master.sys.databases

This the preferred approach now, rather than dbo.sysdatabases, which has been deprecated for some time.


Execute this query:

SELECT name FROM master.dbo.sysdatabases 

or if you prefer

EXEC sp_databases 
like image 127
Ben Hoffstein Avatar answered Oct 06 '22 11:10

Ben Hoffstein