Question : SQL Server Identity Column Leading Zeros

Can I have my (int) identity column 6 numeric characters?

like this:
000001
000002
000003
000010
000011
000100

Answer : SQL Server Identity Column Leading Zeros

a identity field is numerical data type (int ... )
numerical data types don't allow leading "0" ...
so, you need 2 columns ... 1 being int/identity, and the second one being a computed column, using the other column, and formatting it as you need it:

1:
alter table yourtable add formatted_key = right( '000000' + cast(your_identity_key as varchar(10)), 6)
Random Solutions  
 
programming4us programming4us