Search code examples
c#sql-servert-sqlguiduniqueidentifier

Will NEWID() in T-SQL and System.Guid.NewGuid() create the same key?


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!


Solution

  • As Wikipedia writes: UUIDs are for practical purposes unique.

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