Problem description: today is the first time data is run after the new system is launched. It needs to be compared with the tables run by the old system. In the same way, the project runs OK, and the new system reduces manual intervention and increases by 80 age points. First run the data in the old system and import it to a backup table. Run it again with the new system. The quantity is the same as that in the backup table. I think it's easy
Problem description: today is the first time data is run after the new system is launched. It needs to be compared with the tables run by the old system. In the same way, the project runs OK, and the new system reduces manual intervention and increases by 80 age points. First run the data in the old system and import it to a backup table. Run it again with the new system. The quantity is the same as that in the backup table. I think it's easy
Problem description:
Today is the first time data is run after the new system is launched. It needs to be compared with the tables run by the old system. In the same way, the project runs OK, and the new system reduces manual intervention and increases by 80 age points. First run the data in the old system and import it to a backup table. Run it again with the new system. The quantity is the same as that in the backup table. I feel a bit open. The following method is used to compare whether each row of data is the same:
SELECT
COUNT (0)
FROM
(
SELECT * FROM table_nm_bac
UNION
SELECT * FROM table_nm
)
The table table_nm_bac and table table_nm contain 10 thousand data records. The results of the preceding query are.
Stage: SQL SERVER 2008
Solution:
Because it is impossible to produce less union results than each table, the following method is used immediately:
SELECT
COLUMN_NM1,
COLUMN_NM2
...
FROM
Table_nm
EXCEPT
SELECT
COLUMN_NM1,
COLUMN_NM2
...
FROM
Table_nm_bac
GO
SELECT
COLUMN_NM1,
COLUMN_NM2
...
FROM
Table_nm_bac
EXCEPT
SELECT
COLUMN_NM1,
COLUMN_NM2
...
FROM
Table_nm
GO
In this way, the results of both queries are empty. I am relieved. Later, I checked the data again using the following query and concluded that it was because union removed the repeated data in the table:
Select count (0) FROM (
Select distinct * FROM table_nm)
GO
SELECT
COUNT (0)
FROM
(
SELECT * FROM table_nm
UNION
SELECT * FROM table_nm
)
GO
The data after DISTINCT is the same as the data after UNION.
Conclusion: It is better to compare whether the data in the two tables is consistent using the except t method, because the two union operations will remove the duplicate data in the table.