Are Guids guaranteed to be unique?

后端 未结 3 774
后悔当初
后悔当初 2021-01-21 08:31

I\'m using Guids as primary keys in my database and was wondering if it is ever possible that a duplicate Guid might be generated. Are Guids guaranteed to be unique?

3条回答
  •  醉梦人生
    2021-01-21 09:02

    While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small.

    You can check more info on that here.


    A possible solution to avoid duplicate guids (if you still want one) is to use the UNIQUE constraint.

提交回复
热议问题