且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户特定的自动生成代码

更新时间:2023-09-24 23:13:46

你可以看看这个...



使用NVARCHAR / VARCHAR数据类型的自动递增ID [ ^ ]



您需要解决并需要根据您的要求进行更改。


试试这样



  CREATE   TABLE  dbo.TestTable 
(ID INT IDENTITY 1 1 PRIMARY KEY
name int
FormatColumn AS RIGHT ' LS_00' + CAST(ID AS VARCHAR 8 )), 6 )PERSISTED


insert into TestTable(name) values 1
insert into TestTable(名称) 2
insert into TestTable(name) values 3

选择 * 来自 Tes TTable的


Dear i want to generate user specific auto increment code . like

i m creating a lead sheet . than when we submit and save it in database its id should be create like this : LS_001 for next entry . it should be , LS_002

can you please check it out this...

Auto-incremented ID with NVARCHAR/VARCHAR datatype[^]

you need to work around and need to change accordingly to your requirement.


Try like this

CREATE      TABLE dbo.TestTable
( ID INT IDENTITY(1,1) PRIMARY KEY,
name int ,
  FormatColumn AS RIGHT('LS_00' + CAST(ID AS VARCHAR(8)), 6) PERSISTED
)

insert into TestTable ( name) values (1)
insert into TestTable ( name) values (2)
insert into TestTable ( name) values (3)

select * from TestTable