| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 
 | ALTER proc [dbo].[sp_compareTbl] 
(@Tbl1 sysname,
@Tbl2 sysname)
as
begin
 
create table #comp(Analyse varchar(20),
                Tbl sysname,
                col sysname)
 
/* lignes identiques */
insert into #comp 
select 'Colonnes identiques', '*', s1.name
 from syscolumns s1 inner join syscolumns s2
on s1.name = s2.name and s1.id=object_id(@tbl1) and s2.id=object_id(@tbl2) and s1.type=s2.type
 
/* Types différents */
insert into #comp 
select 'Types différents', '*', s1.name from syscolumns s1 inner join syscolumns s2
on s1.name = s2.name and s1.id=object_id(@tbl1) and s2.id=object_id(@tbl2) and s1.type<>s2.type
 
 
/* Colonnes surnuméraires */
insert into #comp 
select 'Colonne surnuméraire', @Tbl1, name 
from syscolumns
where name not in (select name from syscolumns where id=object_id(@tbl2))
and id=object_id(@tbl1)
 
/* Colonnes manquantes */
insert into #comp 
select 'Colonne surnuméraire', @Tbl2, name 
from syscolumns
where name not in (select name from syscolumns where id=object_id(@tbl1))
and id=object_id(@tbl2)
 
select * from #comp
 
drop table #comp
end | 
Partager