sql - trying to determine unique identifier for database table -


i have database table many columns , there no specified primary key. there isn't list of super keys either. besides iteratively trying candidate keys/columns, there way me, using sql, try , figure our whether subset of keys can make unique identifier table?

for example, table may have 4 columns first name, last name, address , zip , data see is:

john, smith, 1 main st, 00001   mary, smith, 1 main st, 00001   mary, smith, 2 sub st, 00002 

in case, i'll need first, last , zip unique key.

john, smith, 1 main st, 00001   john, smith, 1 main st, 00001 

in case, there no unique key.

please don't comment on table construction and/or normalization of databases, i'm trying find practical answer. thanks.

this question: besides iteratively trying candidate keys/columns, there way me, using sql, try , figure our whether subset of keys can make unique identifier table?

you cannot find if combination "can" make primary key. can find if 1 make primary key existing set of data.

to find if set of fields candidate or not, can count distinct of fields (using group-by rollup) , compare count (*)


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -