Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can I set auto increament format to 0001 ?? in ms sql server 2005
Posted
Updated 27-Jun-12 12:35pm
v2
Comments
lewax00 27-Jun-12 18:36pm    
Please don't post in all caps, on the internet that is considered shouting, and won't help you get any answers.
syed armaan hussain 28-Jun-12 11:50am    
oops m sorry ! i apologise

You could insert a trigger on the table. This trigger could contain logic to generate custom primary keys for you.
This kind of key cannot, however, be generated directly by setting auto-increment to true.
 
Share this answer
 
hi try this

SQL
CREATE TABLE tablename(
  id int(5) unsigned zerofill NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (id)
);


it will add
0001
0002....etc

hope it works
accept answer if it works..
 
Share this answer
 
v2
you can't - the auto increment is an integer

and, you really don't want to ... make it the responsibility of the SP or client code to format the number the way you want

That only allows your 9999 rows in your DB before your id's start to wrap though
 
Share this answer
 

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