How do i produce a unique key of length for the most part 12 character with one of these characteristics: Title, Father's title, Mother's title, Birth date, Host to birth.
Thanks ahead of time :)
The primary, and actually only, attribute of the unique identifier is it is exclusive (inside the scope of consideration, be the table, the schema, or global). Integrating any "real life" values into this kind of id doesn't seem sensible.
You need to produce a unique constraint around the characteristics you mention, if you are certain individuals characteristics distinctively describe an individual. This mixture of characteristics forms the "natural key" on the table.
The initial ID is really a "surrogate key", a handy handle that helps you save from needing to specify all of the posts of the natural type in joins with this table. The way you get yourself a unique ID is database dependent. In Oracle, for example you could utilize a sequence in conjunction with an place trigger.
The initial constraint around the natural key will stop you from placing exactly the same person two times, however, you should certainly look into the table first to ascertain if the individual already is available. If that's the case, make use of the ID which was already designated in the future. You are able to, obviously, mix this right into a procedure in which you provide your fields and it'll return the ID, hiding the action of searching up, or creating it whether it's new after which coming back the brand new ID.
Even individuals posts most likely aren't sufficient to become unique, and also, since an individual's title can alter (with marriage, choice, etc), I typically wouldn't use that to develop a unique key.
I typically make use of a surrogate, as an autonumber/identity/sequence or perhaps a UUID/GUID, based upon needs.
That isn't a vital you describe, but a brief bit of structured data that you would like to make use of rather than a vital. Possibly more helpfully:
-- would you like to have the ability to recover individuals characteristics from the given 12-character key ?
-- are you pleased to only produce a key given individuals characteristics ?
If you want same characteristics to create exactly the same key, concatenate all characteristics to some string, calculate a
SHA1 hash and trim first
This isn't certain to be unique, but
50% possibility of a hash collision is going to be at
3.3E+14 values that is ample.
If you do not need this, only use a surrogate
hmm.. which DBMS?
Anyway, Concatenate these strings with caused by the UUID MySQL function, and execute a CRC32 function around the result.
Then, take away the very first 12 figures.