Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to add a 16 digit auto incremental field in sql? I would like to create an application in vc 2010 which has 3 fields, name, date of birth and pincode. If user gives all the information including the pin code, it should be inserted in the database. But the unique id field will be updated automatically with the pincode (6 digit)+ 16 digit.. For instance, if the user gives the pincode as 641001 then, it should be added as 6410010000000001, and if another user with same pin code enters the details, then it should be added as 6410010000000002. And if another user with different pincode 552145 then it should be added as 5521450000000001.. and so on.. It should check for pincode if already exists, then add 1 to the last digit and update it. and it should be unique.

1 solution

I don't recommend to do that (trying to put several informations in your primary field).

Why don't you use a simple integer primary key, and store your pincode/rank in another column ?

The goal of a primary key is to identify a unique record without ambiguity ; trying to put more informations in it will give you more problems than it will solve.

Plus, primary keys are indexed ; if you use a large value as a primary key, you will suffer huge performance losses due to maintenance of index.

So I'm not going to give a solution to your problem the way you have analyzed it. You should review your design and stick to well-known good practices regarding database design.
Share this answer
Gokulnath007 28-Feb-13 8:18am    
How about for 12 digits?
phil.o 28-Feb-13 8:23am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900