0

I know that if you use NEWID() in SQL itself will not create repeated keys.

And the same goes for NewGuid() within C# environment.

But how about do it on both side?

Such as create a NewGuid() and insert it into SQL Server table in part of the code and call NEWID() in another part of the code.

Will they create the same key, no matter how unlikely it is, and cause trouble!?

Much appreciated!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PiggyChu001
  • 440
  • 6
  • 20
  • 1
    `NEWID` and `NewGuid()` will generate a new value every time they are called. The chances of either creating the same value in separate calls is so small that it might as well be impossible. – Thom A Jul 30 '20 at 16:07
  • So it's "possible"!? @.@ – PiggyChu001 Jul 30 '20 at 16:10
  • @PiggyChu001: here is more information on GUID collision (duplication): https://blog.stephencleary.com/2010/11/few-words-on-guids.html#:~:text=Assuming%20a%20perfect%20source%20of,That's%20a%20lot. – Pete -S- Jul 30 '20 at 16:11
  • @PiggyChu001 the probability is around the same as `Guid.NewGuid()` [will generate duplicates](https://stackoverflow.com/a/1705604/2501279). – Guru Stron Jul 30 '20 at 16:11
  • OK! I guess the answer is "It's possible but the chance is so astronomically small that it would be idiotic of me to worry about it"! Thanks for y'all! ^O^ – PiggyChu001 Jul 30 '20 at 16:14

1 Answers1

0

As Wikipedia writes: UUIDs are for practical purposes unique.

It doesn't matter if it is generated by two different methods.

Thomas Koelle
  • 3,416
  • 2
  • 23
  • 44