Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
This is my statement for my table

SQL
SELECT       id, name, department
FROM         auto


I want to make my id column is auto increment start from 001.
I already try this >>

ALTER TABLE dbo.auto AUTO_INCREMENT=001

but its doesn't work

Thanks
Posted
Updated 3-Nov-13 16:21pm
v2

1 solution

Refer - SQL Identity with leading padded zeros[^].
Quote:
SQL
create table Identitytest(
    number int  identity(1,001) not null,
    value varchar(500)
)

But it will store them as 1, 2, 3 ...

If you want to show them by leading zeros, then follow the answer...
Quote:
If you want to display your number column with leading zeros, just pad it in your SELECT statement. It's a number, it will NOT store with leading zeros as an integer.

SQL
SELECT RIGHT('00000' + CAST([number] AS varchar(5)) , 3)
FROM IdentityTest

The 3 is the number of characters you want total in the output display.
 
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