Cut and Paste Code

This is just a little reminder to not be so lazy.  I know it’s quick and easy to cut and paste code, especially for reports.  It saves a lot of time and you can really burn through projects that way.  But you just have to consider what you’re doing.  Just because a section of code worked well before, that doesn’t mean that it’ll work well here.  Look before you leap.  If you want to cut and paste code, go ahead, but at least look at it to make sure it’s actually what you need. 

Recently, I ran across a group of SPs that were clearly from the same template.  They all pulled 150+ cols into #tables, and used only a couple of them.  The theory behind it was the original author needed a few cols, and the rest of the authors only needed a couple, but since they were included in the select * the original guy pulled in, they decided to just leave it at that.  It’s nothing but laziness people.  Look at what you need and get it.  A DB is like a buffet.  You can eat all you want, but eat all you take.  If you need logic from a query, that’s fine, but you should only use that query to help you cut some of your work, not to replace it. 

So, do the work, think about what you need, and do what’s right.  And another thing… cut and paste code leads to some other really bad things.  Like in the case of this code I just fixed.  Not only did the SP get cloned, it wasn’t good code to begin with.  So, instead of the other report writers figuring out how to write the queries themselves, and possibly stumbling on a better way, they just pushed the same bad code out there.  Don’t just assume that because code is published in the DB, that it’s good.  Take the code if you need it, but only take what you can use, and definitely check it somehow to make sure it’s written well to begin with.  If you don’t know how to check it, there are plenty of resources.  Start with your own DBAs, and if you can’t get any love there, try the internet… books… training CDs… user groups… seminars… newsgroups, etc…

Database Spam

I love this. I logged into my Blogger account about 3 weeks ago to post a blog and they had a message up saying that they had a new version with all these new features. I upgraded because it sounded cool, and the first thing they did was mark my blog as spam and disable it.

I filled out the form to get it turned back on and it just came up today. I always pays to upgrade.

Don’t Blow it Off

From time to time I get saved only by the grace of good practice. I’ve got this server that has had fairly unreliable backups for a while now. It’s really hit or miss as to whether the whole thing will be backed up on any given day. Yesterday was one of those days when the backups failed. It was very tempting to just let it go and have it pick up the backups the next day, but I bit the bullet and did what it took to run the backups by hand instead. What can I tell you… last night, the NOC guy who runs the ETL process messed up and hosed 2 DBs on that server. At 2:30am I got a call that both of those DBs had to be restored. I was able to restore and get things back on track in just a few mins.

Take a page out of my book and never blow off backups. You never know when you’ll be called on to restore. Anything can happen at any time and you need to be ready. I know sometimes it’s a beating to make sure the troublesome backups complete, but one day it’ll really save the day… and maybe your job.

Remember, a DBA is only as good as his last backup.

Ken’s New Book

I just got my copy of Ken Henderson’s new book and dispite everything I have to do, I’ve already started tearing into it. Understand though the he just edited it, he didn’t write it. This promises to be every bit as significant as his other books though and it’ll be the next book I review. I just pushed it up in the queue (since MSPress is taking so long to send the others I’ve ordered).

Anyway, once I get it posted, I’ll let you guys know.

Upgrade Madness

We recently ran into a very interesting anomoly here upgrading to Yukon. We have the following query.

Select * from DWStsging.dbo.history

Of course, you all know the 3 part naming convention, so you know that DWStsging is the database name. However, what you may not know is that it’s misspelled. The real name is DWStaging, and the one in the query is mistyped.

So what makes this interesting? SQL2K runs it just fine, and has for months, while Yukon spits it back at us. It’s these little things that upgrading interesting.

These are the kinds of things I really don’t mind though. Sure, it’s nice that 2K does what you mean, and not necessarily exactly what you say, I’d rather my DB not make assumptions like that. So if anything, Yukon is forcing us to clean up our code where we didn’t even know we had problems.

Jerry Springer of Databases

I just started a new project with a new group of devs. I feel like Jerry Springer because they’re just spoiled children. They half-ass everything they do, and then run to the boss when things don’t get sorted out right away.
It’s amazing to me that these people can even function in society. I spend my time settling petty disputes, and fixing things that should have been thought through to begin with.

They constantly overwrite each other’s code and blame it on someone else. They never backup tables before making major changes. They never verify SQL statements before asking me to run them. And most of it’s just ridiculous crap.

You would think that since they have to work in their own dev environment, that they would manage it the way they need to, but instead they do the DB equivalent of sleeping with their cousins, and cheating on their sisters with their moms.

Let’s grow up a little bit and start acting like we know what we’re doing people. If you know the statement isn’t correct then don’t send it anyway. If you know there’s a possibility you’ll need to roll back a change, then backup the table first.

Here’s the code for you:
Select * into NEWtable from ORIGtable

you can get fancier if you like, but that basic statement will get you by. Of course, if you wanna actually backup the DB first, that would be even better. LiteSpeed has object-level recovery so you should be able to pull back individual tables and schema code.

Stop running around like children making half-ass changes. Learn from your mistakes. If it keeps coming back to bite you (and it does), then stop doing it. You’ll find you’ll start making your deadlines and even getting to bed on time.

Darwin Award Followup

Man, this kind of thing just doesn’t go public very often, but it’s just great. I often wonder how many people sleep their way to the top because of the complete lack of skill they show in their position. Anyway, not only do I maintain Tonya’s Darwin Award for extremely horrific decisions, I now have to come up with some other award… something that captures the amount of sleeze that Tonya appears to be. What do you say guys… maybe a Technology Pornstar Award, or maybe the Wettest Technology Award… I look forward to getting some good suggestions from you guys, and I’ll assign the award once we land on a name.

Anyway, a reader brought this to my attention. It was printed in the Dallas Observer. Here’s the link to the actual article though I’ve copied it below.
http://www.dallasobserver.com/blogs/?p=180

March 22, 2006
Communication Breakdown
Filed under: News
In a rare piece of good news for the Dallas County Jail, InfoIntegration, the infamously incompetent computer firm that lost track of inmates like they were old pairs of tube socks, will not renew its contract when it expires in July. Tonya Brenneman, the founder of the firm, got the lucrative contract the old-fashioned way—on her back, according to a fine story in D magazine that had her admitting to sleeping with the man who wrote the contract for the county.

Whistling, as always, past the graveyard, Dallas County Commissioner Mike Cantrell told The Dallas Morning News that InfoIntegration was the victim merely of bad publicity–as opposed to, say, an unqualified CEO. “In my opinion, they did a good job,” he said.

Unable to adjust his opinions to the wealth of information at hand, Cantrell sets the bar rather low considering that thanks to InfoIntegration, dozens of inmates languished in the jail long after their sentence was completed. The News’ James O’Neill did a Pulitzer-worthy piece exposing the company, jail and county for this total system breakdown that in essence imposed an additional punishment above and beyond what the judge ordered. (Attorney David Finn reprints the story on his blog.)

Last December, we chronicled the sad plight of Rhenia Chavers, incarcerated at the jail for the high crime of driving with a suspended license. Chavers was behind bars while the InfoIntegration system was just working out a few kinks–no big deal, really, except that her own son couldn’t locate her. He called the jail staff, and they said they had no idea where she was. She kind of needed to talk to him. While at the jail, Rhenia Chavers did not receive her Lupus medication and suffered a stroke shortly after her incarceration. When I last talked to her in December, she still had trouble walking.

Then there was the plight of Scott Williams, who wound up at the jail last February on a DUI charge. InfoIntegration lost track of him too, and he wound up at the jail for over a week. We chronicled how good a time he had while he was incarcerated without his HIV medication and his partner unable to come to his aid. A few highlights:

“Williams says that inmates wrote their names in shit on the walls, and a water fountain was the waste receptacle of choice for one inmate with diarrhea.

‘There was shit on the toilets. When I’m talking shit, I’m talking an inch of shit,’ he says. ‘I just squatted over it and pushed and tried to aim as best I could.’”

Williams said that because he wasn’t eating sandwiches provided to him, he was forced to strip naked and move to a suicide cell. He shivered for 12 hours, lying on the floor without a blanket while trying to avoid shattered glass on the floor of his cell. Because he hadn’t been receiving his medicine for depression and anxiety, he suffered through an agonizing withdrawal. At night, he’d hear inmates who weren’t receiving their prescribed drugs bang noisily on their cells in protest. –Matt Pulle

Instead of working, I blog.