Pros and Cons of autoincrement keys on “every table”

前端 未结 9 766
误落风尘
误落风尘 2020-12-09 12:54

We are having a rather long discussion in our company about whether or not to put an autoincrement key on EVERY table in our database.

I can understand putting one o

9条回答
  •  情深已故
    2020-12-09 13:14

    You add surrogate auto increment primary keys as part of the implementation after logical design to respect the physical, on-disk architecture of the db engine.

    That is, they have physcial properties (narrow, numeric, strictly monotonically increasing) that suit use as clustered keys, in joins etc.

    Example: If you're modelling your data, then "product SKU" is your key. "product ID" is added afterwards, (with a unique constraint on "product SKU") when writing your "CREATE TABLE" statements because you know SQL Server.

    This is the main reason.

    The other reason a brain dead ORM that can't work without one...

提交回复
热议问题