Esta es la contestación más completa que encomtrarás dar, pero mírala detenidamente y analiza si es compatible a tu trabajo.
Ejemplo 1: tablas de comparación de sql para diferencias
-- Find the different tables and columns between DB_NBR_1 and DB_NBR_2-- (just replace DB_NBR_1 and DB_NBR_2)select isnull(db1.table_name, db2.table_name)as[table],
isnull(db1.column_name, db2.column_name)as[column],
db1.column_name as scripts_col_name
,db1.column_type as scripts_col_type
,db1.column_precision as scripts_col_precision
,db2.column_name as liquid_col_name
,db2.column_type as liquid_col_type
,db2.column_precision as liquid_col_precision
from(select schema_name(tab.schema_id)+'.'+ tab.name as table_name,
col.name as column_name
,y.name as column_type
,y.precisionas column_precision
from[DB_NBR_1].sys.tablesas tab
innerjoin[DB_NBR_1].sys.columnsas col
on tab.object_id = col.object_id
JOIN sys.types y ON y.user_type_id = col.user_type_id
) db1
fullouterjoin(select schema_name(tab.schema_id)+'.'+ tab.name as table_name,
col.name as column_name
,y.name as column_type
,y.precisionas column_precision
from[DB_NBR_2].sys.tablesas tab
innerjoin[DB_NBR_2].sys.columnsas col
on tab.object_id = col.object_id
JOIN sys.types y ON y.user_type_id = col.user_type_id
) db2
on db1.table_name = db2.table_name
and db1.column_name = db2.column_name
where(db1.column_name isnullor db2.column_name isnull)orderby1,2,3
Ejemplo 2: SQL compara datos de dos tablas
select*from tableA
minus
select*from tableB
Aquí puedes ver las comentarios y valoraciones de los lectores
Puedes estimular nuestra misión poniendo un comentario o puntuándolo te damos las gracias.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)