Thursday, July 30, 2015

How to compare two tables schema by SQL query in MS SQL?

How to compare two tables schema  by SQL query in MS SQL?
SELECT name,system_type_id,user_type_id,max_length,precision,scale,collation_name,is_nullable into #Tablescehma1
FROM sys.columns WHERE object_id = OBJECT_ID('TABLE1')

SELECT name,system_type_id,user_type_id,max_length,precision,scale,collation_name,is_nullable into #Tablescehma2
FROM sys.columns WHERE object_id = OBJECT_ID('TABLE2')

select * from #Tablescehma1
except
select * from #Tablescehma2