Link to home
Start Free TrialLog in
Avatar of Jim Metcalf
Jim MetcalfFlag for United States of America

asked on

Query not working as expected

I have a query that is supposed to return table name and last time it was touched and display the tablename and last update

for some reason under table name... it is returning null as its value
can someone correct the query please

SELECT OBJECT_NAME(OBJECT_ID) AS TableName, last_user_update
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'DATBASENAME')
AND last_user_update >= '2015-04-13 13:07:00'
--AND OBJECT_ID=OBJECT_ID('test')
Avatar of Mark Ely
Mark Ely
Flag of United States of America image

You misspelled Database

DB_ID( 'DATBASENAME')  

should be

DB_ID( 'DATABASENAME')
SELECT OBJECT_NAME(OBJECT_ID) AS TableName, last_user_update
FROM sys.dm_db_index_usage_stats
GROUP BY OBJECT_NAME(OBJECT_ID),last_user_update
ORDER BY last_user_update DESC
Avatar of Jim Metcalf

ASKER

that was just an example of a database name... not needed to be spelled correctly
SOLUTION
Avatar of Mark Ely
Mark Ely
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial