Can a sql server table have two identity columns?

前端 未结 9 1849
孤城傲影
孤城傲影 2020-11-27 06:23

I need to have one column as the primary key and another to auto increment an order number field. Is this possible?

EDIT: I think I\'ll just use a composite number a

9条回答
  •  余生分开走
    2020-11-27 06:59

    A workaround would be to create an INSERT Trigger that increments a counter.

    So I have a table that has one identity col : applicationstatusid. its also the primary key. I want to auto increment another col: applicationnumber

    So this is the trigger I write.

     create trigger [applicationstatus_insert] on [ApplicationStatus] after insert as 
           update [Applicationstatus] 
           set [Applicationstatus].applicationnumber =(applicationstatusid+ 4000000) 
           from [Applicationstatus] 
           inner join inserted on [applicationstatus].applicationstatusid = inserted.applicationstatusid
    

提交回复
热议问题