SQL Server compare results of two queries that should be identical

前端 未结 6 2004
面向向阳花
面向向阳花 2020-12-24 11:14

I am modifying a sql server 2005 stored procedure slightly for performance, and I would like to quickly make sure the old stored proc and the new one return the exact same r

6条回答
  •  悲&欢浪女
    2020-12-24 11:46

    EXCEPT is the key to compare two querys (as @jabs said).

    SELECT count(*), * FROM "query 1 here"
    EXCEPT
    SELECT count(*), * FROM "query 2 here"
    

    Adding count(*) for each query to make sure both have the same results. Just in case there are some repeated rows which are deleted by except.

提交回复
热议问题