我想要插入多个记录到一个表中,我希望主键开始为ITS0001
,然后为每个记录增加1。例如:
Record 1 = ITS0001
Record 2 = ITS0002
Record 3 = ITS0003
Record 4 = ITS0004
Record 5 = ITS0005
我怎样才能做到这一点?
我认为不可能在一列中完成,但可以在两列中完成。第一个是行号,第二个是计算列:
观察下面的例子:
create table Table1 (
number int identity(1,1) NOT NULL,
ajusted_number as 'ITS' + REPLICATE('0', 4 -
LEN(number)) + cast(number as varchar(4)) PERSISTED,
Value int
)
SQL小提琴