Democratic Underground Latest Greatest Lobby Journals Search Options Help Login
Google

SQL pet peeve

Printer-friendly format Printer-friendly format
Printer-friendly format Email this thread to a friend
Printer-friendly format Bookmark this thread
This topic is archived.
Home » Discuss » The DU Lounge Donate to DU
 
Commie Pinko Dirtbag Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:20 PM
Original message
SQL pet peeve
NEVER rely on field order in a table!

This is EVIL:

INSERT INTO mytable VALUES(my_id, my_name, my_ssn)

This is GOOD:

INSERT INTO mytable (id, name, ssn) VALUES(my_id, my_name, my_ssn)

That was you CPD IT rant of the day. We now return to our scheduled programming
Printer Friendly | Permalink |  | Top
LSK Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:24 PM
Response to Original message
1. i ran into that a few weeks ago
Sometimes you can get away with it when making a backup of a table.

insert into backup_table values select * from original_table
Printer Friendly | Permalink |  | Top
 
DS1 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:30 PM
Response to Original message
2. HAH! Loser
When I make a new table I have a script that inserts every ASCII variation possible into the fields. That way when I want to single out a row of possible data, I run a Delete FROM where the row != to the data I want to keep. Then the stored procedure makes a NEW table with all the data in it, just with a 1 tacked onto the end of the table name.

It does wonders for performance.
Printer Friendly | Permalink |  | Top
 
billyskank Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:34 PM
Response to Reply #2
4. That is the stupidest thing I have ever heard
Well done! :thumbsup:
Printer Friendly | Permalink |  | Top
 
DS1 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:45 PM
Response to Reply #4
6. Thank you
:bounce:
Printer Friendly | Permalink |  | Top
 
billyskank Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:51 PM
Response to Reply #6
8. Actually, it's the second stupidest thing I've heard
The stupidest thing I ever heard actually happened, at my previous job. We commissioned this system from a Dutch firm (I think they must have been based next door to an Amsterdam headshop, or something) to allow us to dial and remotely read electricity meters.

Every meter has a number of meter channels, and some bright spark thought that it would be a major performance hack to have every set of meter channels in its own table! Yes, one table per meter. The database was queried using dynamic SQL.
:bounce:

It's the only database I've ever seen where you needed to put hints in to query the data dictionary. :o

Woe betide you if you tried to browse the schema using TOAD.....chug...chug...chug... x(
Printer Friendly | Permalink |  | Top
 
DS1 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 04:51 PM
Response to Reply #8
13. wow
But I maintain my idea is dumber - unless you have a dedicated transaction log server that can keep up with a few hundred billion or so rows of changes per user event :D
Printer Friendly | Permalink |  | Top
 
UncleSepp Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:32 PM
Response to Original message
3. SQL peeve of the day for me...
Writing pieces of a filter clause into a join:
...
from Table1
inner join Table2 on
Table1.Key = Table2.Key
and Table2.CodeForGodKnowsWhat = 42
...

Now imagine about thirty of those in a single stored proc, written several years ago, by a guy who wasn't a dev, and has now left to sail the world or ride yaks or anything else but support his code. Argh!

Printer Friendly | Permalink |  | Top
 
no name no slogan Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:36 PM
Response to Original message
5. SQL is for wussies
flat files, now THAT's where it's at
Printer Friendly | Permalink |  | Top
 
DS1 Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:45 PM
Response to Reply #5
7. My ISAM would kick your txt files ass!
Printer Friendly | Permalink |  | Top
 
billyskank Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 03:53 PM
Response to Reply #7
9. Come now, break it up
Because as we all know, Real Programmers use Fortran.

http://www.pbm.com/~lindahl/real.programmers.html
Printer Friendly | Permalink |  | Top
 
no name no slogan Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 04:03 PM
Response to Reply #9
10. Fortran? FORTRAN?
Screw that! I just flip the switches on the front of the box in a pre-determined order and watch the LEDs light up.

I bet you even use punchcards, too, huh? Wuss. :silly:
Printer Friendly | Permalink |  | Top
 
billyskank Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 04:04 PM
Response to Reply #10
11. Well that is pretty hardcore
I do have to admit. :)
Printer Friendly | Permalink |  | Top
 
no name no slogan Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 04:08 PM
Response to Reply #11
12. Whew, I thought you were going to say "Luddite"
;)
Printer Friendly | Permalink |  | Top
 
Ellen Forradalom Donating Member (1000+ posts) Send PM | Profile | Ignore Tue Oct-11-05 05:13 PM
Response to Original message
14. It seems so obvious
Yet I've maintained such INSERT statements. I know about them because the rug was yanked out from under them after a little 'ALTER TABLE' statement and I had to go clean it up.
Printer Friendly | Permalink |  | Top
 
DU AdBot (1000+ posts) Click to send private message to this author Click to view 
this author's profile Click to add 
this author to your buddy list Click to add 
this author to your Ignore list Thu Apr 25th 2024, 08:24 AM
Response to Original message
Advertisements [?]
 Top

Home » Discuss » The DU Lounge Donate to DU

Powered by DCForum+ Version 1.1 Copyright 1997-2002 DCScripts.com
Software has been extensively modified by the DU administrators


Important Notices: By participating on this discussion board, visitors agree to abide by the rules outlined on our Rules page. Messages posted on the Democratic Underground Discussion Forums are the opinions of the individuals who post them, and do not necessarily represent the opinions of Democratic Underground, LLC.

Home  |  Discussion Forums  |  Journals |  Store  |  Donate

About DU  |  Contact Us  |  Privacy Policy

Got a message for Democratic Underground? Click here to send us a message.

© 2001 - 2011 Democratic Underground, LLC