views:

22

answers:

1
-- find last usage info, 
-- how far back this information goes depends on the 
-- server/database settings

select --
ss.name as SchemaName, so.name as SprocName
,so.create_date as SprocCreated, so.modify_date as SprocModified 
,so.object_id
,stat.last_user_seek,stat.last_user_scan,stat.last_user_lookup,stat.last_user_update
,stat.last_system_seek,stat.last_system_scan,stat.last_system_lookup, stat.last_system_update
from sys.objects so

inner join sys.schemas ss on so.schema_id=ss.schema_id

left join sys.dm_db_index_usage_stats stat
on so.object_id=stat.object_id

where ss.name<>'sys' and so.type='P' 
union 
select 
ss.name as SchemaName, so.name as SprocName
,so.create_date as SprocCreated, so.modify_date as SprocModified 
,so.object_id
,stat.last_user_seek,stat.last_user_scan,stat.last_user_lookup,stat.last_user_update
,stat.last_system_seek,stat.last_system_scan,stat.last_system_lookup, stat.last_system_update
from db_dit.dbo.sys.objects so 

inner join sys.schemas ss on so.schema_id=ss.schema_id

left join sys.dm_db_index_usage_stats stat
on so.object_id=stat.object_id

where ss.name<>'sys' and so.type='P'
order by case when stat.object_id is null then 0 else 1 end,ss.name,so.name

I'm trying to validate that my sproc changes from dev were pushed to sit properly in a simple query, but I can't seem to query the sys tables on the other db I get Invalid object name 'db_dit.dbo.sys.objects'.

+2  A: 

instead of db_dit.dbo.sys.objects it is db_dit.sys.objects

sys is already the schema, no need for dbo

example

select * from tempdb.sys.objects s1
    join msdb.sys.objects s2 on s1.name = s2.name
SQLMenace
I could swear I tried this, but when I did I must have made mistakes when I introduced `[]` around parts of it to try to get it to work.
Maslow
+1 ah simple mistakes.
Maslow