Guid.NewGuid() VS a random string generator from Random.Next()

后端 未结 7 1645
攒了一身酷
攒了一身酷 2021-02-01 17:51

My colleague and I are debating which of these methods to use for auto generating user ID\'s and post ID\'s for identification in the database:

One option uses a single

7条回答
  •  南方客
    南方客 (楼主)
    2021-02-01 17:54

    Regarding your edit, here is one reason to prefer a GUID over a generated string:

    The native storage for a GUID (uniqueidentifier) in SQL Server is 16 bytes. To store a equivalent-length varchar (string), where each "digit" in the id is stored as a character, would require somewhere between 32 and 38 bytes, depending on formatting.

    Because of its storage, SQL Server is also able to index a uniqueidentifier column more efficiently than a varchar column as well.

提交回复
热议问题