tags:

views:

47

answers:

2

I have W2k3 SBS running SQL 2005. I want to delete a SQL db. How can I tell if it is being used?

Thanks.

+2  A: 

You can use

select db_name(dbid) [database],T0.* from master..sysprocesses T0 WHERE  db_name(dbid)='your database'

To see users and process connected to the database.

RRUZ
Thanks very much. Very useful query.
A: 

You let the server run for long enough to catch any activity, then you look into the last_user_xxx columns in sys.dm_db_index_usage_stats for tables in your database. Any SELECT or INSERT/UPDATE/DELETE on any table during the lifetime of a server process will leave its imprint on those columns.

Remus Rusanu
Thanks very much.