When having an identity column is not a good idea?

后端 未结 8 491
深忆病人
深忆病人 2021-01-12 04:06

In tables where you need only 1 column as the key, and values in that column can be integers, when you shouldn\'t use an identity field?

To the contrary, in

8条回答
  •  温柔的废话
    2021-01-12 05:10

    I'm not sure I understand enough about your context, but I interpret your question to be:

    "If I need the database to create a unique column (for whatever reason), when shouldn't it be a monotonically increasing integer (identity) column?"

    In those cases, there's no reason to use anything other than the facility provided by the DBMS for the purpose; in your case (SQL Server?) that's an identity.

    Except:

    If you'll ever need to merge the table with data from another source, use a GUID, which will prevent duplicate keys from colliding.

提交回复
热议问题