2011-06-03 59 views
0

按照MSDN,它们描述System.Guid.NewGuid()作为..的GUID的System.Guid

The chance that the value of the new Guid will be all zeros or equal to any other Guid is very **low** 

会不会是一个坏主意,设定的customerID Customer表,以“唯一标识符”,并生成使用System.Guid.NewGuid()的唯一ID?我如何确保该方法只会生成唯一的ID?

+0

[随机是如何System.Guid.NewGuid()?](http://stackoverflow.com/questions/467271/how-random-is-system-guid-newguid) – 2011-06-03 11:02:03

回答

2

除非你有很好的理由使用Guid作为ID,否则我会建议不要使用Guid作为关键。 Guids在数据库中占用大量空间,并且在常见情况下不会带来好处。另外他们在索引方面表现不佳。

为什么不将CustomerID设置为整数并将其设置为在插入新记录时自动生成其值?