Wednesday, 29 June 2011

List all databases with sqlcmd

sqlcmd -s <db server or instance> -q "exec sp_databases"

Examples:
 sqlcmd -s localhost -q "exec sp_databases"
 sqlcmd -s dbserver -u loginname -p password -q "exec sp_databases"
 sqlcmd -s ./MSSQLSERVER -u loginname -p password -q "exec sp_databases"



4 comments:

Web Hosting Jaipur said...

I admire the valuable information you offer in your blog post. Keep up the good work.
Web Hosting Jaipur

StartUpFounder said...

You can also use free command line tool "SQLS*Plus" which is like an Oracle SQL*Plus for SQL Server.

To show all database you just use command "show dbs".

sqlsplus works with SQL Server 2008, 2005 and 2000 and very flexible with variables (&, &&), data formatting (set lines size, pagesize, etc), etc - much better alternative to sqlcmd or isql

I found sqlsplus at http://www.sqlsplus.com

Anonymous said...

Hello,

I have SQL Express installed on a server and it is case sensitive. If you are logged in as a user with permissions in the instance, you can use this line:

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>sqlcmd -S localhost\SQLEXPRESS -E

otherwise, use

C:\Program Files\Microsoft SQL Server\100\Tools\Binn>sqlcmd -S localhost\SQLEXPRESS -U username -P password

Michale Daniel said...

Well It Was Very Good Information For Linux Learners.i Was Really Happy See This Information We Are Also Provide Linux Online Training All Courses.