我想在表中插入多个记录,我希望主键以ITS0001
开头,然后为每条记录增加1。例如:
Record 1 = ITS0001
Record 2 = ITS0002
Record 3 = ITS0003
Record 4 = ITS0004
Record 5 = ITS0005
我怎样才能做到这一点?
答案 0 :(得分:2)
我认为不可能在一列中制作它,但你可以在两列中完成。第一个是行号,第二个是计算列:
请注意以下示例:
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
)