如何在sql2008中为ID自动增加? [英] how to make an auto increment for ID in sql2008 ?
问题描述
这是我对我桌子的陈述
SELECT id ,名称,部门
FROM auto
我想要让我的id列从001开始自动递增。
我已经尝试过这个>>
ALTER TABLE dbo.auto AUTO_INCREMENT = 001
但它不起作用
谢谢
请参阅 - 带有前导填充零的SQL标识 [ ^ ]。
Quote:
create 表 Identitytest(
number int identity ( 1 , 001 )不 null ,
value varchar ( 500 )
)
但它会将它们存储为1,2,3 ...
如果你想用前导零显示它们,那么按照答案...
引用:如果要显示
数字
带有前导零的列,只需在SELECT
语句中填充它。它是一个数字,它不会以前导零作为整数存储。
SELECT RIGHT (' 00000' + CAST([number] AS varchar ( 5 )), 3 )
FROM IdentityTest< br $>
3
是输出显示中你想要总数的字符数。
This is my statement for my table
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
Refer - SQL Identity with leading padded zeros[^].
Quote: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 yourSELECT
statement. It's a number, it will NOT store with leading zeros as an integer.
SELECT RIGHT('00000' + CAST([number] AS varchar(5)) , 3) FROM IdentityTest
The3
is the number of characters you want total in the output display.
这篇关于如何在sql2008中为ID自动增加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!