The last day of 2014, today when importing data to the database, there is a problem, is the joint primary key to go heavy.
The thing is, there is a table m, I want to find a table that imports a lot of data, and I need to set the fields a (int) and B (int) union as the primary key.
But when I set the primary key, I was told I had duplicate content and couldn't set the primary key.
Normally, the combination of these two fields is unique and should not be duplicated, in order to find duplicate data and see what is wrong.
Adopt distinct Way
But found
Select COUNT (distinct name, id) from A
This sentence in SQL does not apply, http://www.cnblogs.com/rainman/archive/2013/05/03/3058451.html this inside write, of course, SQL will also error.
So only two fields can be converted and re-assembled into a single field for querying
Select cast(A as varchar(Ten))+cast(B as varchar(Ten)) Newkey fromMGroup by cast(A as varchar(Ten))+cast(B as varchar(Ten)) having Count(cast(A as varchar(Ten))+cast(B as varchar(Ten)))>1
The code itself is not difficult, that is, to convert the idea, can not only focus on the two int type of primary key, re-assemble to facilitate the query.
SQL Federated primary Key check weight