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