List Databases MSSQL

To list all databases on a Microsoft SQL Server (or MSDE, of course) via OSQL or whatever, use this:

exec sp_helpdb

However, that spits out really wide columns of data that are awkward in an interactive OSQL session... this option is easier to read, but it is unsupported:

SELECT name FROM master..sysdatabases ORDER BY name

-----------

 

To list the logical files in a sql server database in interactive OSQL sessions, try this:

Use mydb;
go
select * from sysfiles;
go

---------

Some other options:
http://www.aspfaq.com/show.asp?id=2456

tags: SQL, Server, MSSQL, osql

Related Scribbles:
  • Attach / Detach Database OSQL Example
  • SQL Server - Move a database manually via SQL
  • Restore and Backup MSDE Database with TSQL via OSQL
  • Quickly Shrink SQL Server Transaction Logs
  • SQL Server


  • ID: 726
    Author:
    leonard
    Date Updated:
    2010-09-16 15:00:04
    Date Created:
    2005-12-24 16:13:03

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> List Databases MSSQL
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.