对比两个数据库中相同的表不同的索引

对比两个数据库中相同的表不同的索引

USE db1
--实现将sqlserver数据库的索引全部查出,包括索引名
select  a.name as tabname
       ,h.name as idname
INTO #t
FROM  sys.objects    as  a 
right join sys.indexes  as h  on  a.object_id=h.object_id
 where  a.type<>'s'  
 --AND a.name='accountRecord'
 ORDER BY tabname
 GO

USE db2
--实现将sqlserver数据库的索引全部查出,包括索引名
select  a.name as tabname
       ,h.name as idname
INTO #t1
FROM  sys.objects    as  a 
right join sys.indexes  as h  on  a.object_id=h.object_id
 where  a.type<>'s'  
 --AND a.name='accountRecord'
 ORDER BY tabname
 GO

 SELECT * INTO #t2 FROM #t WHERE tabname IN (SELECT DISTINCT tabname FROM #t1)
 SELECT * FROM #t
 SELECT * FROM #t1 ORDER BY tabname
 SELECT * FROM #t2 ORDER BY tabname

 select * INTO #t3 FROM #t1 except select * from #t2
 select * INTO #t4 FROM #t2 except select * from #t1

 select * INTO #t5 FROM #t2 INTERSECT select * from #t1

 SELECT * FROM #t3
 SELECT * FROM #t4
 SELECT * FROM #t5

 

posted @ 2015-12-24 16:50  davidhou  阅读(1095)  评论(0编辑  收藏  举报