Solved

SQL Database Question

Posted on 2013-01-10
4
319 Views
Last Modified: 2013-01-21
SQL 2008

(Getting there slowly team, thank for all the help so far!)

OK I would like to try and see if over half of my database are actualy being used.
My plan is to put them off line and see if someone shouts. Then when they do ask them what they were doing and then I know what its doing.

But looking I can see I can do a search on the database and look at the modify date.

Example

I have a database "NSMRulestat"
I found a command or Query is that what you SQL guys call it.

USE NSMRulestat
GO
SELECT name, modifydate
FROM sys.objects
GO

It comes back with this

Query
Are these tables within the database?
How would you find out what they are?
0
Comment
Question by:Bransby-IT
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
jacreji earned 400 total points
ID: 38763351
Try using this query to get the last accessed date for the database :

SELECT DatabaseName, MAX(LastAccessDate) LastAccessDateFROM    (SELECT        DB_NAME(database_id) DatabaseName        , last_user_seek        , last_user_scan        , last_user_lookup        , last_user_update    FROM sys.dm_db_index_usage_stats) AS PivotTableUNPIVOT     (LastAccessDate FOR last_user_access IN        (last_user_seek        , last_user_scan        , last_user_lookup        , last_user_update)    ) AS UnpivotTableGROUP BY DatabaseName  HAVING DatabaseName NOT IN ('master', 'tempdb', 'model', 'msdb')ORDER BY 2

The query that you are using is for all objects including the system tables and procedures as well.
0
 
LVL 3

Author Comment

by:Bransby-IT
ID: 38763830
Thanks for the Query, I cant get it to run, when I copy and paste it to notepad it goes funny.
0
 
LVL 1

Expert Comment

by:jacreji
ID: 38763859
Try it now.. this should work

SELECT DatabaseName, MAX(LastAccessDate) LastAccessDate FROM    
(SELECT DB_NAME(database_id) DatabaseName ,
 last_user_seek ,
 last_user_scan ,
 last_user_lookup  ,
 last_user_update    
 FROM sys.dm_db_index_usage_stats) AS PivotTable UNPIVOT
 (LastAccessDate FOR last_user_access IN
 (last_user_seek,
  last_user_scan,
  last_user_lookup,
  last_user_update))
  AS UnpivotTable GROUP BY DatabaseName  
  HAVING DatabaseName NOT IN ('master', 'tempdb', 'model', 'msdb') ORDER BY 2
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 100 total points
ID: 38767925
The objects listed are all system tables/views.

To look for activity, it's better to query "sys.tables", since it shows only user tables:

SELECT name, modifydate
FROM sys.tables
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now