Is using MS SQL Identity good practice?

前端 未结 5 1000
囚心锁ツ
囚心锁ツ 2021-02-09 23:56

Is using MS SQL Identity good practice in enterprise applications? Isn\'t it make difficulties in creating business logic, and migrating database from one to another?

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-10 00:40

    Personally I couldn't live without identity columns and use them everywhere however there are some reasons to think about not using them.

    Origionally the main reason not to use identity columns AFAIK was due to distributed multi-database schemas (disconnected) using replication and/or various middleware components to move data. There just was no distributed synchronization machinery avaliable and therefore no reliable means to prevent collisions. This has changed significantly as SQL Server does support distributing IDs. However, their use still may not map into more complex application controlled replication schemes.

    They can leak information. Account ID's, Invoice numbers, etc. If I get an invoice from you every month I can ballpark the number of invoices you send or customers you have.

    I run into issues all the time with merging customer databases and all sides still wanting to keep their old account numbers. This sometimes makes me question my addiction to identity fields :)

    Like most things the ultimate answer is "it depends" specifics of a given situation should necessarily hold a lot of weight in your decision.

提交回复
热议问题