Thursday, October 29, 2009

Clean up SQL database use command line tools

There are some SQL server command line tools are installed in C:\Program Files\Microsoft SQL Server\80\Tools\Binn folder. OSQL.exe can connect to the database and execute SQL query on it.

The usage of OSQL.exe is
OSQL /u username
system will pop up for password, after authentication. we can type in SQL query and execute them on the server.
for example

To release unused database space:
DBCC SHRINKDATABASE (local, 80 TRUNCATEONLY)
GO

To find a database name:
select db_name(0) [0 is the database index number]
Go

No comments: