С этим запросом у вас есть все столбцы с одинаковыми именами в разных таблицах вашей БД:
select object_name(c.id) + '.' + c.name + ' '
+ t.name
+ case when t.xtype = t.xusertype then '' else '[' + tr.name end
+ case
when tr.name in ('bit', 'tinyint', 'smallint', 'int', 'bigint',
'float', 'money', 'smallmoney', 'real', 'date', 'time',
'datetime', 'datetime2', 'smalldatetime', 'timestamp')
then ''
else
case when isNull(c.prec,0)=0 then ''
else '('
+ case when c.prec = - 1 then 'MAX' else cast(c.prec as varchar) end
+ case when c.scale is null then '' else ',' + cast(c.scale as varchar) end
+ ')'
end
end
+ case when t.xtype = t.xusertype then '' else ']' end
+ case when t.collationId <> c.collationId
then ' collate ' + c.collation collate Latin1_General_BIN else '' end
+ case c.isnullable when 0 then ' not null' else '' end
+ case c.colstat
when 1 then ' identity(' + Cast(Ident_seed(o.name) as varchar)
+ ',' + cast(Ident_incr(o.name) as varchar) + ')'
else ''
end
+ case when cm.text is null then ''
else ' default '
+ case when patindex('% as %', cm.text) > 0
then rtrim(substring(cm.text, patindex('% as %', cm.text) + 4, len(cm.text)))
else substring(cm.text, 2, len(cm.text) - 2)
end
end
as Columns
from syscolumns c
join systypes t on (t.xusertype = c.xusertype)
left join systypes tr
on (tr.xtype = t.xtype and tr.xusertype = t.xtype)
join sysobjects o
on (o.id = c.id)
left join syscomments cm
on (cm.id = c.cdefault)
where c.name in (
select cl.name
from syscolumns cl
join sysobjects ob on (cl.id = ob.id and ob.xtype = 'U')
group by cl.name
having count(*) > 1
)
order by c.name