Is there any way to find unused SQL Server 2005 databases ?
I'm in the process of upgrading and migrating my server into SQL Server 2008 x64 in new server instance from 2005 32 bit.
Not a fool proof way. A couple of things that spring to mind are.
See which databases have few pages in the buffer pool
select db.name, COUNT(*) As page_count
from sys.databases db LEFT JOIN sys.dm_os_buffer_descriptors bd ON db.database_id = bd.database_id
group by db.database_id, db.name
order by page_count
Or look at the index usage stats for each database
SELECT db.name,
(SELECT MAX(T) AS last_access FROM (SELECT MAX(last_user_lookup) AS T UNION ALL SELECT MAX(last_user_seek) UNION ALL SELECT MAX(last_user_scan) UNION ALL SELECT MAX(last_user_update)) d) last_access
FROM sys.databases db
LEFT JOIN sys.dm_db_index_usage_stats iu ON db.database_id = iu.database_id
GROUP BY db.database_id, db.name
ORDER BY last_access
You could also use logon triggers to log access ongoing for a certain period just to be sure that nothing seems to be accessing "dead" databases before switching them offline.
With SQL Server 2005, you can use the dynamic management view sys.dm_db_index_usage_stats. The name says "index" but that's a little misleading - every table has an entry in here, even if it doesn't have any indexes. Here's a useful query from SQL Magazine:
SELECT
t.name AS 'Table',
SUM(i.user_seeks + i.user_scans + i.user_lookups)
AS 'Total accesses',
SUM(i.user_seeks) AS 'Seeks',
SUM(i.user_scans) AS 'Scans',
SUM(i.user_lookups) AS 'Lookups'
FROM
sys.dm_db_index_usage_stats i RIGHT OUTER JOIN
sys.tables t ON (t.object_id = i.object_id)
GROUP BY
i.object_id,
t.name ORDER BY [Total accesses] DESC
Here's the original article:
http://www.sqlmag.com/Article/ArticleID/53878/sql_server_53878.html
Keep in mind that these usage statistics reset when SQL Server restarts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With