Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Database Question

Posted on 2013-01-10
4
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
jacreji earned 1600 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 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 400 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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