TSQl 除了验证
您好,我正在用 TSQL 编写一个很长的程序,该程序从旧的(并且非常脏的数据集)中提取数据,清理数据并重新格式化输出,包括列标题以匹配新的数据集新表和旧表中有 130 列。为了测试的目的,我从每个中引入 100k 行。为了验证表结构和字段属性是否相同,我的老板要求我使用 TSQL EXCEPT。我进入我们的 2008 年服务器并从新表 2005 数据中提取数据,并从 2008 年旧归档数据中提取数据。
我使用的代码如下:
SELECT * FROM #NEW_TABLE
EXCEPT
SELECT * FROM #OLD_TABLE
EXCEPT 语句输出新表中的所有 100k 记录。我是否正确,这是因为数据不匹配,而不是表结构问题,因为我根本没有收到任何错误。
Hi I am writing a long program in TSQL that pulls in data from an OLD (and very dirty data set) scrubs the data and reformats the output including column headers to match a new data set There are 130 columns in both the new and old tables. For the purpose of testing I am bringing in 100k rows from each. To validate that the table structures and field attributes are the same my boss has asked me to use the TSQL EXCEPT. I got onto our 2008 server and pulled in the data from new table 2005 data and data from the 2008 old archived data.
The code I am using is as follows:
SELECT * FROM #NEW_TABLE
EXCEPT
SELECT * FROM #OLD_TABLE
The EXCEPT statement outputs all 100k records from the new table. Would I be correct that this is because there is no match in the data, rather than table structure issues as I am receiving no errors at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的 - 据我了解,您会获得新表上的所有记录,因为它们都不与旧表上的记录匹配(目的除外)
Yes - as far as I understand you get all the records on the new table because none of them match the ones on the old table (purpose of EXCEPT)
这是正确的,但这取决于你所说的“匹配”是什么意思。
为了使 EXCEPT 正常工作,两个表中的所有列都必须匹配,才能将其从结果集中删除。这意味着,如果您有类似以下内容的内容:
并且将 EXCEPT 与以下内容一起使用:
您仍然会看到输出:
That's correct, but it depends on what you mean by "match".
In order for EXCEPT to work, all columns must match from both tables in order for it to be removed from the result set. That means that if you have something that looks like:
and you use EXCEPT with the following:
You will still see as your output: