- 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
At least they broke it out into a separate table. :-)
Last company I was at... We had a table which contained 4 columns which were used as accumulators. There was another table which had a list of what would be summed up for each of these 4 columns.
Accumulator1 Accumulator2 Accumulator3 Accumulator4
Someone decided that the users may not want to be limited by 4 columns. They may want more. They may want 36 options!
So the developer added additional columns to the table.
Accumulator1 Accumulator2 Accumulator3 Accumulator4 ... Accumulator0 AccumulatorA AccumulatorB ... AccumulatorZ
When I saw this, I just about flipped out. It was another year and a half before I finally quit. I kept telling myself I could improve things. :-)
Admin
Admin
So the first admin is optional and admin_user2 is mandatory? How logical.
Admin
Dave's not here, man!
TRWTF is you need to get "Bob from AccountTemps, Knurlman."
Admin
For the love of god stop letting developers design anything. They can't. We know this. Sure they can type in stuff called "code" which usually does a half ass job of making peoples lives better and a full ass job of making them want to rip the developer to pieces.
Development managers are even worse. They will put together an "architecture" that has more to do with the tools they have a religious experience with than with anything resembling actual business requirements.
I've seen too many applications put together by developers with little to no oversight. Usually a business requirement will come up, that was completely foreseeable but apparently wasn't something the dev even considered: like the example in the story. Then, rather than "fix" the problem the right way, they spend hours arguing how it is too hard to change or not "feasable" or what have you then proceed to make things worse.
Admin
Still using SQL and relational databases? Haven't people learned anything?
Admin
Or just "we don't want to pay you what you're worth"
Admin
Definition of a DBA: A failed developer who still thinks he/she can write code.
Admin
The rules of normalization say that if you have a repeating group, you should break this out to a separate table.
So that's what they did. The repeating group is now in another table.
Admin
Because if you have a choice between, say, buying a car that runs for $15,000 or a car that doesn't run for $10,000, obviously the second choice is the more efficient and economical one. Any discussion of how much it will cost to get it running, or if that is even possible, is irrelevant. It is a car, it is cheaper, therefore it is the better choice.
Admin
Yes, I've learned that:
(a) SQL sucks
(b) Everything I've seen that's an alternative to SQL sucks bigger
Admin
So then who is going to design? You say developers can't. You say management can't. If you actually read the article, you know that DBA can't since they made it worse.
All this story needed was someone with knowledge or experience to review the proposed database design at the beginning and say, this is a many to many relationship, it should be a cross reference. No more story.
Admin
That's how my ticketing system does it for a couple fields. Well, it's even better than that -- it's a semi-colon separated list. Reporting on this single large, very wide table is awesome.
Admin
Version 2:
Admin
As well as whoever at my last project did this years ago to our report generation table (a table with over 1 bn rows, and the only reliable way to join the table was to regex the column for the other table's PK).
Admin
The max(admi1) is explained by the join using a group-by; so a function is required.
But I can't explain the use of a group-by. Well actually I can in that they don't know what they are doing.
I like this book: The Art of SQL, http://shop.oreilly.com/product/9780596008949.do
Admin
what the hell are you talking about? you think that no developers know anything about databases just because of the clueless SOB in the story?
Admin
Sure, Oslo deserves a place in hell.
I see this technique is quite common: Using varchar to store all kinds of beasts. They even name it "serialized data". Here's the contents of one of my rows (we use CLOBS directly).
e[=]1[|]v[=]tx4[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]4[|]v[=]tx4[|]a[=]9[|]c[=]0[|]p[=]10[||]e[=]5[|]v[=]tx4[|]a[=]2[|]c[=]0[|]p[=]6[||]e[=]6[|]v[=]tx4[|]a[=]2[|]c[=]0[|]p[=]6[||]e[=]7[|]v[=]tx4[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]1[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]4[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]10[||]e[=]5[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]6[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]7[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]8[|]v[=]mch16[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]1[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]4[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]10[||]e[=]5[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]6[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]7[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]8[|]v[=]mch26[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]1[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]4[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]10[||]e[=]5[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]6[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]7[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]8[|]v[=]ch48[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]1[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]4[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]10[||]e[=]5[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]6[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]6[||]e[=]7[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]0[||]e[=]8[|]v[=]mv7[|]a[=]9[|]c[=]0[|]p[=]0
Admin
BREAKING NEWS: the majority of DBAs are clueless fucks who couldn't join their hands to their arses in the dark.
In other news: water is wet, space is cold, and people are stupid.
Admin
this is going to end well
Admin
Admin
Then there's "Jake". Then there's "Jake from StateFarm".
Admin
What about serialized classes saved as files?
Admin
Look at StackOverflow. The majority of "n00bs" asking about SQL write horrible SQL
Admin
Well.
Admin
I think that if you wrote your response in complete sentences, it would justify your point better.
It reads like this:
This post does nothing to differentiate developers and DBAs.
Admin
Me too. Sadly I get to work on a production database that has this in almost every table:
The original "developers" and "DBA" wanted to use these cool new GUID things they heard about as the primary key for EVERY table. Unfortunately they had not also heard about UNIQUEIDENTIFIER and so obviously varchar is the next sensible choice.
And of course these keys are all in a CLUSTERED INDEX.
Sigh.
Captcha: incassum -- Incassum da firum, breakum da glassum
Admin
This. I don't know how many times I've had some form of the following conversation:
Boss: "Application XYZ doesn't work. How much will it cost to develop a replacement."
Me: "Fifteen thousand."
Boss: "But Application XYZ only cost twelve thousand! Can't you come down a little?"
Me: "I thought you said Application XYZ doesn't work."
Boss: "That's right."
Me: "Oh, I misunderstood the requirements. I can develop something that doesn't work for ten thousand."
Admin
Why wouldn't you have a clusterf*ck in a clustered index?
Admin
Reminds me of the time I had to do the reverse: the table had a whole bunch of numbered columns, and only a few of them were usually used. The resulting report only printed 2 records per page because it was printing all of those empty fields.
After (very briefly) considering re-engineering the database to put each row in a separate table and link the tables with a key (it would have required completely redesigning the data entry form, which had lots of text boxes), I rolled up my sleeves and typed this instead:
It looks ugly and takes longer to run (12 times longer, to be exact), but the resulting report uses a lot less paper.
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Holy hell how many tdwtf programmers for a it take to fix the html encoding on the RSS feed?
Admin
Is this a joke I didn't get or is it meant seriously?
Admin
If you're going to quote "SQL Antipatterns", you should really cite it. (That's antipattern #1, for readers.)
TRWTF, for those devs, is that the "applications" table doesn't store the application admin password, unencrypted of course. (Antipattern #20).
ought to do it.
Admin
Why is everyone accepting the left outer join or any outer join? Every column in application_admins is not null.
This can be done with a simple (inner) join: (Sure, you get only one admin per line, but it handles N-admins!)
select applications.name, attribute, listen_port, AD.admin from applications join application_admins AD;
Admin
You're probably eating memory or disk swapping! Drop the ORDER BY and I'll bet it runs much faster.
Admin
If you need senior people just to know the basics that anyone fresh out of school should know, I start to weep a bit. Just a bit.
Admin
One can never tell. On the off chance that someone's reading this for a solution the best solution is 4 tables:
applications: Columns: id, name, port (all not null) Primary Key: id Constraints: name and port are unique (or probably should be anyway)
users: Columns: id, username, password (all not null) Primary Key: id Constraints: username is unique
application_roles: Columns: id, application_id, rolename (all not null) Primary Key: id Constraints: combination of application_id and rolename are unique
application_user_roles: Columns: id, application_id, user_id, role_id (all not null) Primary Key: id Constraints: combination of application_id and user_id is unique
Now you can assign a user to multiple applications, assign multiple users of any roles you want to a single application, and implement more roles than just "admin" and "user" without breaking any other applications.
Although if you're certain you'll always only have users and admins you could get away with 3 by ditching the roles table and replacing application_user_roles with this:
application_users: Columns: id, application_id, user_id, is_admin (all not null) Primary Key: id Constraints: combination of application_id and user_id is unique
But I can almost guarantee as soon as you do it someone is going to ask for some level of access between user and admin.
Admin
One can never tell. On the off chance that someone's reading this for a solution the best solution is 4 tables:
Now you can assign a user to multiple applications, assign multiple users of any roles you want to a single application, and implement more roles than just "admin" and "user" without breaking any other applications.
Although if you're certain you'll always only have users and admins you could get away with 3 by ditching the roles table and replacing application_user_roles with this:
But I can almost guarantee as soon as you do it someone is going to ask for some level of access between user and admin.
Admin
FTFY
Admin
Admin
Admin
select AllWork, NoPlay, Johnny, DullBoy, J1.johnny1, J2.johnny2, J3.johnny3, J4.johnny4, J5.johnny5, J6.Johnny6, J7.Johnny7, J8.Johnny8, J9.Johnny9 from JohnnyDullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny1) as johnny1 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J1 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny2) as johnny2 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J2 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny3) as johnny3 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J3 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny4) as johnny4 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J4 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny5) as johnny5 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J5 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny6) as johnny6 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J6 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny7) as johnny7 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J7 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny8) as johnny8 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J8 using DullBoy left outer join (select DullBoy, MIN(Here_Is_Johnny9) as johnny9 from Johnny where Work = 1 AND Play = 0 group by DullBoy) as J9 using DullBoy