解决方法
您可以尝试以下查询
select count(<potential_column>),count(distinct <potential column>) from <table>
当计数匹配时,您有一个候选键供考虑.
例如,如果我有一个名为PEOPLE的人员表,我可能会做类似的事情.
select 'FullName' as FldName,count(fullname) as Tot,count(distinct fullName) as TotD from People union select 'SSN' as FldName,count(SSN) as Tot,count(distinct SSN) as TotD from People
这将返回两行,显示字段名称和计数. tot匹配totd的任何行都是候选者,尽管在这个例子中,我依赖于基于数据知识的SSN(社会安全号码).
您可以使用连接字段运行相同的查询,例如
select 'First/Last' as FldName,count(Firstname+lastName) as Tot,count(distinct firstname+LastName) as TotD from People
如果您正在寻找复合键,虽然尝试决定连接哪些字段需要更好地了解您的数据