SQL Server - Auto-incrementation that allows UPDATE statements

前端 未结 5 2010
礼貌的吻别
礼貌的吻别 2020-11-30 15:22

When adding an item in my database, I need it to auto-determine the value for the field DisplayOrder. Identity (auto-increment) would be an ideal solution, but I need to be

5条回答
  •  [愿得一人]
    2020-11-30 16:10

    One thing you should do is to add commands so that your procedure's run as a transaction, otherwise two inserts running at the same time could produce two rows with the same value in DisplayOrder.

    This is easy enough to achieve: add

    begin transaction
    

    at the start of your procedure, and

    commit transaction
    

    at the end.

提交回复
热议问题