Wednesday, February 1, 2012

DB structure compare query

select distinct s1.type,s1.type_desc,count(s1.type)
FROM sys.objects s1 with(nolock)
left join sys.objects s2 with(nolock) on s2.object_id = s1.parent_object_id
where s1.name not like '%__SQLXMLB%' and s1.type not in ('IT','SQ')
group by s1.type,s1.type_desc

-------------------------------------------------------------------------------------

SELECT distinct s1.name,s1.type,s1.type_desc,s2.name as parentname
FROM sys.objects s1 with(nolock)
left join sys.objects s2 with(nolock) on s2.object_id = s1.parent_object_id
where s1.name not like '%__SQLXMLB%' and s1.type not in ('IT','SQ')
order by s1.type,s1.name

No comments: