我已经通过用户定义的函数重构了一些视图,我想确保它们是相同的。
我写了一个小脚本来测试这种情况:
SET ANSI_NULLS OFF
GO
SELECT TOP 1000 [DealNumber]
,...others
FROM OLD_VIEW
EXCEPT
SELECT TOP 1000 [DealNumber]
,...others
FROM NEW_VIEW
当我应用它时,我获得了许多行作为结果。但是,如果我从任何行中获取 DealNumber 并运行以下命令:
SET ANSI_NULLS OFF
GO
SELECT [DealNumber]
,...others
FROM OLD_VIEW
WHERE DealNumber = 'MyDealNumber'
EXCEPT
SELECT [DealNumber]
,...others
FROM NEW_VIEW
WHERE DealNumber = 'MyDealNumber'
正如预期的那样,这将返回一个空记录集。
作为一种替代方法,我编写了一个函数 Test_View_Correctness 来执行前一个测试。但是,如果我这样运行它:
SELECT TOP 1000 [DealNumber] from OLD_VIEW
where DealNumber IN (SELECT a.DealNumber
FROM Test_View_Correctness(DealNumber) as a)
如何确保 except 方法有效?