- 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.
Admin
You should rethink the value of those 25 years.
The reason to think that UUIDs are not truly unique is to suppose that the keys are just random and then wave your hands and say "Birthday Paradox" to summon a collision.
In actuality, you need to generate a trillion-trillion UUIDs (by random generation) to have a 10% chance of collision.
Furthermore, UUIDs are not generally generated by a random process.
In order to actually have a collision, you'll need to do one or more of the following:
No guesses which method you've been using.
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!
Admin
We can see a form of "symptomatic programming" here. The test starts failing? Remove the test! This calculation should give 19, but often it gives 20, sometimes 21, what to do? Hardcode the expected value! There are warnings? Ignore them, they're not errors. I also made a new UUID, should solve the problem now: ÐÈADBËËF–ØØ24—ÁFFE-199€-407708154711000Ä.
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.
Edit Admin
No sure what you are talking about, there's only one way two generate UUIDs in .net, the purely random classical variant and the v7 which is way more prone to collisions due to their smaller randomness scope.
For starters, if you never encounter collisions then either you only do small scale hobby projects or you are working with project that actually don't properly log collisions because they happen in practice - a lot. And it is easily explained way, first off you number roughly translate to the whole scope which is not the case, because as I mentioned before there are different version which different probabilities. In fact a few version have long been deem obsolete because they were even back in the 90s very prone to collisions. And here we end up with the next issues, those are theoretical distributions, even crypto level RNGs without dedicated hardware come nowhere near those distributions especially when you are working in a localized distributed cluster. And finally you don't understand probabilities, they are averages. You can have a million collisions in a row and it would still be perfectly falling the those odds, in fact the whole point of randomness is to not have sequential predictable results.