Forum Discussion

David2312's avatar
David2312
Copper Contributor
Jun 06, 2024

Usage of surrogate keys

is it good practice to always use auto incremented primary keys to identify entities in a relational database. For example if an order is identified by three composite keys (customer_id, orderdateTime, orderItem) shouldn't I just make a new surrogate PK order_id which identifies all other attributes?

1 Reply

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    David2312 the question can't be answered with yes or no.

    For example, you have a table for products and each product do have a unique product number = natural key; whe adding an additional technical key, makes it more complicated.

     

    Or you have a product table for a multi-tenant solution => tenant id + product nummer = surrogate keys

Resources