简体   繁体   English

比较Teradata中两个表的内容的最佳方法?

[英]Best way to compare contents of two tables in Teradata?

When you need to compare two tables to see what the differences are, are there any tools or shortcuts you use, or do you handcode the SQL to compare the two tables? 当您需要比较两个表以了解它们之间的区别时,是否使用了任何工具或快捷方式,或者您是否手工编写了SQL以比较两个表?

Basically the core features of a product like Red Gate SQL Data Compare (schemas for my tables typically always match). 基本上,诸如Red Gate SQL数据比较之类的产品的核心功能(我的表的方案通常总是匹配的)。

Background: In my SQL Server environment, I created a stored procedure which inspects the metadata of the two tables/views, creates a query (as dynamic sql) which joins the two tables on the specified key columns, and compares data in the compare columns, reporting key differences and data differences. 背景:在我的SQL Server环境中,我创建了一个存储过程,该过程检查两个表/视图的元数据,创建一个查询(作为动态sql),该查询将指定键列上的两个表联接在一起,并比较compare列中的数据,报告关键差异和数据差异。 The query can either be printed and modified/copied or just excecuted as is. 该查询既可以打印和修改/复制,也可以直接执行。 We are not allowed to create stored procedures in our Teradata environment, unfortunately. 不幸的是,我们不允许在Teradata环境中创建存储过程。

Sounds like a data profiling tool such as Talend's Open Profiler would make the most sense at that point. 听起来像Talend的Open Profiler这样的数据分析工具在那时最有意义。

You could write a BTEQ statement that builds the query similar to your SQL Server stored procedure and then export the dynamically built SQL. 您可以编写一个BTEQ语句来构建类似于SQL Server存储过程的查询,然后导出动态构建的SQL。 You can then in turn run that inside of your BTEQ. 然后,您可以在BTEQ内部运行它。 It might get cumbersome, but with enough determination you could probably mock something up. 它可能会很麻烦,但是只要有足够的决心,您就可以模拟一些东西。

I dont know if this is the right answer you are searching for. 我不知道这是否是您正在寻找的正确答案。

sel * from database_name1.table_name1
minus
sel * from database_name2.table_name2;

you can do the same by selecting specific columns. 您可以通过选择特定列来执行相同操作。 This will basically give the non existent rows from table2 which are in table1. 这基本上将给出table1中table2中不存在的行。

If you were not looking for this type of answer, please ignore this and continue. 如果您不是在寻找这种类型的答案,请忽略它并继续。

Also you can select like below. 您也可以像下面这样选择。

select 
table1.keycol1,
table2.keycol2,
(table1.factcol1 - table2.factcol2) as diff
from table1
inner join 
table2
on table1.keycol1 = table2.keycol1
and table1.keycol2 = table2.keycol2
where diff <> 0

This was just an analysis which can give an idea. 这只是可以给出想法的分析。 Please ignore any syntactical and programmatical errors. 请忽略任何语法和程序错误。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM