Database-wide unique-yet-simple identifiers in SQL Server

后端 未结 11 817
余生分开走
余生分开走 2020-12-12 12:50

First, I\'m aware of this question, and the suggestion (using GUID) doesn\'t apply in my situation.

I want simple UIDs so that my users can easily communicate this i

11条回答
  •  再見小時候
    2020-12-12 13:22

    I would implement by defining a generic root table. For lack of a better name call it Entity. The Entity table should have at a minimum a single Identity column on it. You could also include other fields that are common accross all your objects or even meta data that tells you this row is an order for example.

    Each of your actual Order, Delivery...tables will have a FK reference back to the Entity table. This will give you a single unique ID column

    Using the seeds in my opinion is a bad idea, and one that could lead to problems.

    Edit

    Some of the problems you mentioned already. I also see this being a pain to track and ensure you setup all new entities correctly. Imagine a developer updating the system two years from now.

    After I wrote this answer I had thought a but more about why your doing this, and I came to the same conclusion that Matt did.

提交回复
热议问题