开发者

Auto Increment userdefined id

开发者 https://www.devze.com 2023-01-14 04:16 出处:网络
Hi can anyone give me an idea how to create an auto generated id like ED01,ED02 etc., so that when i am entering data the id should be automatic开发者_运维知识库ally incremented Arguably this would be

Hi can anyone give me an idea how to create an auto generated id like ED01,ED02 etc., so that when i am entering data the id should be automatic开发者_运维知识库ally incremented


Arguably this would be better done on the client side but you could

  • create a normal identity column
  • add a computed column doing the formatting.

Test script

DECLARE @ED TABLE (
  ID INTEGER PRIMARY KEY IDENTITY(1, 1)
  , UserID AS 'ED' + CAST(ID AS VARCHAR(32))
  , I INTEGER
)

DECLARE @I INTEGER
SET @I = 0
WHILE @I < 100
BEGIN
  SET @I = @I + 1
  INSERT INTO @ED VALUES (@I)
END

SELECT * FROM @ED
0

精彩评论

暂无评论...
验证码 换一张
取 消