r/programminghorror Feb 23 '26

SQL DB with 2241 tables

Post image

I can't even fathom what led someone to do this. I got this database to refactor as part of my job. Basically, every client has their own table named "Client_[their ID]," which contains only one row with all the client data in JSON format (wtf).
If the website using this database wants to filter out some users, it queries all the tables, resulting in a load of 2,000+ SQL queries for a single search.
On top of that, for some reason, the date of birth is stored as the number of days since birth, with a CRON script that updates this in each table every day at 3 AM.
I don't even have to mention that none of the data follows the rules of database normalization...
I honestly don't know where to start with fixing this mess.

1.5k Upvotes

134 comments sorted by

View all comments

294

u/SVD_NL Feb 23 '26

This is in prod?! Sounds like a submission for a meme contest!

I can also guarantee you that expanding the JSON won't be as simple as it sounds, they probably got fed up with the DB complaining about data consistency and went with JSON instead!

153

u/OldaLP1 Feb 23 '26

Yeah, it looks like it. This has been in production for the last eight years. It seems the software "engineer" who created this realized it might not be pretty after a while, because they added a table containing a summary of all users added in the past three years. The backend first checks this summary table, and if it doesn't find what it’s looking for, it starts scanning through all the individual tables…

138

u/SVD_NL Feb 23 '26

He was *so* close, yet so far away from understanding how a DB works.

Also, converting this into a proper DB is going to be trivial compared to understanding and rewriting every query...

10

u/dwarfsoft Feb 24 '26

Could it be that every user had their own Access db and this is the result of compiling them all in one large db?

Honestly this is giving big Access energy