- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
So this is a design for a table with different types of records? Not surprised the dev then concluded the primary key constraint was the problem. After all, it's the frist thing that comes to mind.
Edit Admin
My response to hearing that would be "well, maybe you should find out what that reason is."
And that, also.
Edit Admin
Q: a Universally Unique Identifier is a 128-bit number, which is 16 bytes binary. Typical text format is "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", 32 hexdigits plus 4 dashes, total of 36 characters. So why VARCHAR(40) instead of CHAR(36)?
A: because it isn't really/always a UUID, they just like the sound of that name.
Edit Admin
Perhaps because they're used to code using 40-character buffers for UUIDs: 36 plus both braces and null-terminator makes 39, usually rounded up to 40 because it's a nice, round number.
So you
#define UUID_BUFFER_SIZE 40
and then you use 40 as well by reflex when creating the table (unless your combination of RDMBS, library and knowledge allows using an UUID type instead).Edit Admin
It could be worse. At the place I work, they would've made it an NVARCHAR. Just in case the hexadecimal text has unicode characters in it, I guess.
Admin
That reminds me of this classic DailyWTF duplicate GUID problem from waaaay back in 2011
https://thedailywtf.com/articles/A-More-Unique-Identifier
Edit Admin
(wide-eyed innocent look)
But hexadecimal text does have unicode characters in it! '0' to '9' and 'a' to 'f' (or 'A' to 'F') are all unicode characters.
(/wide-eyed innocent look)
Edit Admin
The record type looks like if they wanted to map an object oriented design to a database schema, and it defines the actual type. In this case it can only be one, but in others there may be more options, and they keep it for consistency (maybe an auto-generated schema or at least generic queries).
It's super badly named for that, though, and it doesn't make sense to make it a primary key value.
Edit Admin
MSSQL already has a datatype "uniqueidentifier", that is easy to generate and I assume is faster.
This reminds me of opening a DB in SSMS, and seeing columns with True/False values in my own language. "Odd, did not know SSMS localised bit/boolean." No, somebody used strings for that. Case sensitive strings.
Edit Admin
BTSTT. Five years ago, when I first opened the application I'm maintaining now (MVC .NET, MSSQL) and saw "Y" and "N" for one column, I swear I had the same thought. Nope!
[DeletePending] nvarchar NULL
for a value which is /always/ "Y" or "N", never even null or empty or blank. WTF.
Edit Admin
Lovely: my comment is being "held for moderation" . . . despite the fact that I am logged in.
Edit Admin
Someone who knew what they were doing finally seeded a random number generator and committed the change and no one noticed during code review?
Edit Admin
First of UUIDs are not unique, that is a misconception, collisions are highly unlikely. Considering that in my 25 years of professional experience I already witnessed myself a collision TWICE, I'd say whoever things there can't be collision hasn't been in the biz long enough (or never dealt with what is these days called "big data").
Secondly, there's a good reason for composited keys with UUIDs and one example would be soft delete and versioning implementations. Obvious the ENUM in this example is odd, but yes, those tables are by default not simply addressable by a unique ID for obvious reasons. No idea what was here going on but you have always be careful with assumptions especially without knowing the business/use case of code.
Edit Admin
Beyond just the issue of 36 or 40 character "UUID"s as stroings, why VARCHAR which is for storing variable length strings, versus CHAR wich is for fixed-length strings.
Damned good bet that however they choose to format their "UUID"s, they'll all be the same length.
Addendum 2025-07-22 14:22: Gaah. I love typos in non-editable input boxes. Sorry to hurt all your eyes, folks!
Edit Admin
Given the UUID stuff I'm guessing that's SQL Server, which means the reason in both cases is "Microsoft".
You're welcome.