本文介绍了自动递增的用户定义ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,谁能给我一个想法,如何创建一个自动生成的ID(如ED01,ED02等),以便在我输入数据时,该ID应该自动递增
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 automatically incremented
推荐答案
visitCounter++;
textBox1.Text = visitCounter;
这将自动增加值,但如果再次关闭应用程序,它将从启动开始.
This will automatically increment the vale but if you close the application again it will take from starting.
create TABLE ED(
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
根据您的要求尝试此操作
Try this as per your requirement
CREATE
TABLE user(id INT NOT NULL IDENTITY(1,1),
col
AS 'ED'+
RIGHT(
'0'+CAST(id AS VARCHAR(2)),2))
INSERT
INTO userDEFAULT VALUES
SELECT
* FROM user
这篇关于自动递增的用户定义ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!