[{"data":1,"prerenderedAt":198},["ShallowReactive",2],{"blog:2007:using-guids-as-row-identifiers":3,"blogMore-Development":184,"comments-using-guids-as-row-identifiers":197},{"id":4,"title":5,"body":6,"category":166,"commentCount":167,"date":168,"description":169,"excerpt":170,"extension":171,"filenames":172,"hidden":173,"image":172,"meta":174,"minutes":114,"navigation":175,"path":176,"seo":177,"showCategory":172,"stem":178,"tags":179,"updated":172,"url":181,"wordCount":182,"__hash__":183},"content\u002Fblog\u002F2007\u002Fusing-guids-as-row-identifiers.md","Using GUIDs as row identifiers",{"type":7,"value":8,"toc":164},"minimark",[9,21,37,46,55,58,70,140,154,160],[10,11,12,13,20],"p",{},"Wade Wright is ",[14,15,19],"a",{"href":16,"rel":17},"https:\u002F\u002Fweblogs.asp.net\u002Fwwright\u002Farchive\u002F2007\u002F11\u002F04\u002Fthe-gospel-of-the-guid-and-why-it-matters.aspx",[18],"nofollow","preaching that IDs in a database should always be GUIDs"," and lists four reasons. I commented there with my opinions but it hasn’t shown up. Some people like to censor if you don’t agree with them completely. My points addressing each of his four ‘reasons’ were:",[22,23,24,28,31,34],"ol",{},[25,26,27],"li",{},"Avoid round-trips when creating new business objects\nI don’t know about you but I don’t populate my IDs until I persist and not on object creation so this reason is irrelevant.",[25,29,30],{},"Data merging is easy\nYes, this is a good reason to use GUIDs if you know merging is likely to happen.",[25,32,33],{},"Type\u002Ftable ignorance\nBasically he says here that a foreign key reference might relate to a row in any table which breaks relational concepts big time.",[25,35,36],{},"Some weird anecdote I don’t quite get",[10,38,39,40,45],{},"He does acknowledge that querying the database by hand is a bit of a pain but underestimates the ",[14,41,44],{"href":42,"rel":43},"https:\u002F\u002Fwww.sql-server-performance.com\u002Farticles\u002Fper\u002Fguid_performance_p1.aspx",[18],"Guid\u002Funiqueidentifier performance penalty in SQL Server"," especially with regards to INSERTs (might be able to optimize there by having .NET generate the GUID instead of SQL Server).",[10,47,48,49,54],{},"He also fails to consider how a page full of GUIDs will bloat out HTML page size especially if they end up used in a number of full drop-down SELECT boxes or collapsible JavaScript tree on a single page although ",[14,50,53],{"href":51,"rel":52},"https:\u002F\u002Fmsmvps.com\u002Fblogs\u002Fomar\u002Farchive\u002F2006\u002F08\u002F10\u002Fiis-6-compression-quickest-and-effective-way-to-do-it-for-asp-net-compression.aspx",[18],"deflate and GZip compression should take care of that if you’ve turned it on",".",[10,56,57],{},"There are many valid scenarios for using GUIDs as unique identifiers but one size does not fit all using them without consideration will likely lead to somewhere bad ;-)",[10,59,60,61,65,66,69],{},"If you are using them and space is tight such as uncompressed HTML or the GET\u002FPOST size down you can write and parse the Guid as Base64 instead of hex format which cuts a Guid of ",[62,63,64],"code",{},"81187ecf-c452-4550-9ed2-8a51e3c46da1"," (36 bytes) to ",[62,67,68],{},"z34YgVLEUEWe0opR48RtoQ=="," (22-24 bytes) which soon adds up. To do that in C# and .NET simply:",[71,72,77],"pre",{"className":73,"code":74,"language":75,"meta":76,"style":76},"language-csharp shiki shiki-themes everforest-light dracula","string base64 = Convert.ToBase64String(guid.ToByteArray());\nGuid guid = new Guid(Convert.FromBase64String(base64));\n","csharp","",[62,78,79,112],{"__ignoreMap":76},[80,81,84,88,92,96,99,103,106,109],"span",{"class":82,"line":83},"line",1,[80,85,87],{"class":86},"sXAHl","string",[80,89,91],{"class":90},"s6Vpi"," base64 ",[80,93,95],{"class":94},"s9HRq","=",[80,97,98],{"class":90}," Convert.",[80,100,102],{"class":101},"sS4Kt","ToBase64String",[80,104,105],{"class":90},"(guid.",[80,107,108],{"class":101},"ToByteArray",[80,110,111],{"class":90},"());\n",[80,113,115,119,122,124,128,131,134,137],{"class":82,"line":114},2,[80,116,118],{"class":117},"snuxY","Guid",[80,120,121],{"class":90}," guid ",[80,123,95],{"class":94},[80,125,127],{"class":126},"smiwp"," new",[80,129,130],{"class":117}," Guid",[80,132,133],{"class":90},"(Convert.",[80,135,136],{"class":101},"FromBase64String",[80,138,139],{"class":90},"(base64));\n",[10,141,142,143,148,149,54],{},"For a further squeeze you could use ",[14,144,147],{"href":145,"rel":146},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FASCII85",[18],"ASCII85 encoding"," with ",[14,150,153],{"href":151,"rel":152},"https:\u002F\u002Fblog.codinghorror.com\u002Fc-implementation-of-ascii85\u002F",[18],"Jeff Atwood’s ASCII85 implementation in C#",[10,155,156],{},[157,158,159],"em",{},"[)amien",[161,162,163],"style",{},"html pre.shiki code .sXAHl, html code.shiki .sXAHl{--shiki-default:#3A94C5;--shiki-dark:#FF79C6}html pre.shiki code .s6Vpi, html code.shiki .s6Vpi{--shiki-default:#5C6A72;--shiki-dark:#F8F8F2}html pre.shiki code .s9HRq, html code.shiki .s9HRq{--shiki-default:#F57D26;--shiki-dark:#FF79C6}html pre.shiki code .sS4Kt, html code.shiki .sS4Kt{--shiki-default:#8DA101;--shiki-dark:#50FA7B}html pre.shiki code .snuxY, html code.shiki .snuxY{--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic}html pre.shiki code .smiwp, html code.shiki .smiwp{--shiki-default:#F85552;--shiki-dark:#FF79C6}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":76,"searchDepth":114,"depth":114,"links":165},[],"Development",13,"2007-11-06T01:47:08+00:00","Wade Wright is preaching that IDs in a database should always be GUIDs and lists four reasons. I commented there with my opinions but it hasn’t shown up. Some people like to censor if you don’t agree with them completely. My points addressing each of his four ‘reasons’ were:","[object Object]","md",null,false,{},true,"\u002Fblog\u002F2007\u002Fusing-guids-as-row-identifiers",{"title":5,"description":169},"blog\u002F2007\u002Fusing-guids-as-row-identifiers",[180],".NET","\u002Fblog\u002F2007\u002Fusing-guids-as-row-identifiers\u002F",422,"uC0xpZ9jpTlX_OSCQLWzHhCrGTxCLd4cmxHbctUqZjY",[185,189,193],{"title":186,"date":187,"url":188},"Transactions in the MongoDB EF Core Provider","2025-10-25","\u002Fblog\u002F2025\u002Fmongodb-explicit-transactions\u002F",{"title":190,"date":191,"url":192},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","\u002Fblog\u002F2025\u002Fmongodb-queryable-encryption\u002F",{"title":194,"date":195,"url":196},"Lazy Loading with EF Core Proxies","2025-04-02","\u002Fblog\u002F2025\u002Fef-proxies\u002F",[],1780900530888]