Michael J. Swart

October 26, 2009

SQL Snippets is my new favourite thing.

Filed under: Miscelleaneous SQL — Tags: , , — Michael J. Swart @ 8:18 am

Within the last hour, Mladen Prajdić announced a new version of his popular SSMS Tools Pack version 1.7. The main new feature being SQL Snippets. This provides Management Studio an add-in that is very much like the code snippets in other IDEs everywhere.

Also within that last hour, I’ve installed and test-driven the new feature and it is officially my new favourite thing. I’ve got big plans for this feature. I’ve already translated my custom templates to it. In conjunction with templates (and Ctrl-Shift-M), I foresee great things for this feature.

Good job Mladen!

October 4, 2009

Spotlight on Brad Schulz Y'all

Filed under: Miscelleaneous SQL — Tags: , , , , — Michael J. Swart @ 5:46 pm

Every now and then, I come across an idea where I think “Man, I wish I thought of that”

Reading Brad Shulz’s blog post The Age-Old SELECT * vs. SELECT 1 Debate was one of those times. In that blog post, he explains how relevant the select expressions are when used inside an EXISTS’s subquery. By looking at the official docs here: http://technet.microsoft.com/en-us/library/ms188336.aspx you’ll learn enough to get by. But after reading Brad Shulz’s article, you’ll never forget.

Brad is relatively new to SQL Server. He spent much of his career so far focused on Visual FoxPro and was a Visual Foxpro MVP for years. SQL Server is a new focus for him and he’s already moderating the MSDN T-SQL forum. It won’t be long before he’ll be able to create test database servers with one hand tied behind his back (Interesting trick: Sit on your right hand and try typing “create test database servers”.)

His blog http://bradsruminations.blogspot.com/ deserves more exposure. I was first introduced to the articles he writes in September as he syndicated his blog at SQLServerPedia.

His style is sometimes hilarious, and funny most of the time, but always clever. I’m always surprised when SQL Server writers manage to keep their articles engaging because of the subject matter. Brad seems to keep up just fine.

Also Must-Read (if only for the laughs)

Brad recently agreed to answer a number of questions I had. (Huge thanks Brad for taking the time!)

Michael J. Swart: What skills in Visual FoxPro (VFP) transfer easily to SQL Server? (Any surprising ones?)

Brad Schulz: Just working with the concepts of databases, tables, columns, relations, and indexes for many years in VFP makes the transfer easy.  And basic SQL syntax has been part of the VFP language since 1991, so that eliminates an enormous learning curve right away… We VFPers have been doing INSERT, UPDATE, DELETE, and SELECT for almost 20 years.

That being said, though, we would still do a lot of one-row-at-a-time processing, because it was easy and it was lightning fast.  But the equivalent of that in SQL (i.e. cursor) is slow as molasses, and I’ve learned a lot of set-based techniques in SQL Server that I had never used before.  Thank goodness that I started playing with T-SQL recently… I think I would have gone bananas if I had started with SQL2000 with no CROSS APPLY or CTE’s or window functions (i.e. the OVER clause).  How did you guys stay sane before SQL2005 came out?

Michael J. Swart: A common story is that many SQL Server professionals got their start as “accidental DBAs”. How did you get your start? Or how did you come to choose SQL Server as a focus?

Brad Schulz: My story’s not of the accidental variety.  I got a B.S. in Computer Science from USC (University of Southern California) in 1981.  I actually started out as a Building Design major, which is a combination of Architecture and Civil Engineering, but I dropped the Architecture class about a month into my freshman year, because I could see that I had no drawing talent whatsoever.  To fill that void, I ended up taking a FORTRAN class independent study with a Computer Science professor.  I gobbled it up, and finished the class in about 2 weeks.  The professor asked me to be a tutor for others taking the regular class.  I changed my major to Computer Science just before my sophomore year.

When I graduated from college, I immediately started working as a float in my parents’ pool.  But after a couple of months, a friend of the family recommended me to a pear-packing company in Kelseyville, California (I found out later they were the largest pear-packer in the state).  They had a computer system that no longer worked and the software company that custom wrote it for them was out of business.  To make a long story short, they hired me as a consultant (God knows why), and I read the manual on the programming language (a form of BASIC on an HP-250 machine) and ended up re-writing their entire system.  From that point, I got work by word-of-mouth, and I’ve been an independent developer ever since.

I worked in dBase II in the early 1980’s, and then eventually moved to dBase III, Quicksilver, Clipper, and then FoxBase+ and FoxPro.  I’ve found plenty of FoxPro work for more than 20 years, but it’s not going to last forever, so SQL Server seemed like the logical choice to move to.

Michael J. Swart: What motivates you to moderate the MSDN T-SQL Forum?

Brad Schulz: Back in the 1990’s I participated in the FoxForum on CompuServe, answering questions about FoxPro.  I enjoyed helping people, and I learned a lot just by helping others, and I learned new ideas from experts who hung out at the forum.  I wanted to duplicate that experience at the MSDN T-SQL Forum.  I’ve learned an incredible amount from some very talented people there.

Michael J. Swart: What motivates you to blog?

Brad Schulz: For one thing, I wanted to get myself known a little more in the SQL community.  Some of my blogs are humorous or tongue-in-cheek, and that’s just a release for the crazy creative side of me.  But I also enjoy writing “how-to” and “discovery” articles… they force me to practice and experiment more with T-SQL.  I wrote several articles for FoxTalk and FoxPro Advisor in the 1990’s, but the turnaround time took forever, from submission through the editing process, and then waiting months for eventual publication.  In contrast, I like the immediate publication of blog posts and getting immediate feedback.

Michael J. Swart: What’s one thing you can say about yourself that would make the SQL Server crowd say “Nifty”?

Brad Schulz: What’s a word that means “stylish; smart; fine; excellent” and rhymes with “thrifty”?  Okay, scratch that.

Let me see… I’m an adopted child whose birth-mother was German Catholic and who played the violin.  I always knew I was adopted.  My birth-mother had requested I be placed with a German Catholic family (which I was, though my mother was the Catholic and my father was the German).  My parents knew about the violin, and figured there was musical talent in me, so they set me up with piano lessons when I was 5.  I’ve been playing piano ever since (45 years).  The weird, spooky part is that I asked for more detailed non-identifying information from the adoption agency when I was about 25 years old, and when I received it, I was floored when it said that my birth-mother worked in and had a talent for “data processing” (whatever that meant in the 1950’s).  Talk about “nature” vs “nurture”… I think the “nature” argument wins hands-down!

I also have a passion for the stock market, which I discovered in 1998.  You can read more about that at my (now-on-hiatus) website http://www.stockciphering.com/whatis.htm.  The stock market is just one huge database of stocks and daily prices, isn’t it?  And so I wrote a suite of Visual FoxPro (VFP) programs to calculate technical analysis figures for stocks and produce buy signals for them, and I created the website to try to ca
pitalize on it.  The website never really set the world on fire, but in “eating my own dog food” and using the data for my own trading, I did very well… From Jan2003 to Mar2009, my IRA (where I do my trading) more than quadrupled in value, compared to the S&P500 which lost 25% of its value during that same period.

 Michael J. Swart: Thanks Brad

September 16, 2009

What the devil?

Filed under: Miscelleaneous SQL — Tags: , , — Michael J. Swart @ 8:59 pm

The devil you know vs. the devil you don’t.
A good friend of my told me about an issue she recently came across. It seems that a particular group of admins implemented SQL Server database mirroring in order to implement a kind of relatively cheap high availability solution. It’s a useful strategy that’s discussed in a number of places. Here and here for example. 

Well, something went wrong or I wouldn’t be writing right now. I’m not familiar with all of the details, but there was some wrinkles with the performance of the network and the database server became extremely slow. (despite what you might think, this really isn’t an article about database mirroring) It’s ironic that the very thing that was implemented to increase up-time was the cause of down-time.

From another perspective, this is a case of “The devil you know vs. The devil you don’t.” Here, they traded the devil they knew – that is, not having a warm standby server – with a devil they didn’t – in this case, production uptime now depended on network performance in an unexpected way.

Other examples of known vs. unknown devils:

  • Known bugs in version 1.0 vs. Unknown introduced bugs in version 2.0
  • Raid 0 vs. Misconfigured SANs
  • Reliability of municipal power vs. Possibly fawlty UPS systems
  • Add your own examples to the comments! (best two comments get a No-Prize – extra points for irony.)

I’ve actually witnessed the unknown devils above. And as a lover of irony, I smiled (tempered slightly by sympathy for those whose necks were on the line).

The devil is in the details
In the examples I’ve mentioned above, the unknown devils reared their heads because of exposure to an unforeseen risk. What can you do about it though? Well, what else is there to do? Get to know that unknown devil. Test, test, test with all the time and resources available to you. There really is no short-cut. And sometimes, with the right testing, if you’re thorough enough you can get it right…

God is in the details*
Getting it right means you get the high availability you were hoping for. The uninterupted power. Secure systems, the robust bug free software. Maybe even five nines.

I’ll leave you with one last devil you know vs. devil you don’t example. It’s a picture of me and my brother. Presumably you know me and not him. But which is the evil one? Increased difficulty: neither of us have a goatee. Unfair: the photos have been scrambled.

Who’s the evil one?

* — BTW, “God is in the details” is a quote by architect Mies van der Rohe. I’m in good company when quoting architects for this industry; you’ve heard of design patterns right?

August 7, 2009

Intellectual Property Issues on SQL Blogs.

Filed under: Miscelleaneous SQL — Michael J. Swart @ 9:26 am
Late last week I got an email from a guy preparing to give a Sql Server seminar. He asked whether it would be okay if he used a drawing I did in an earlier blog post (with attribution of course). I’m not sure I replied in time for the seminar.
So since I’m glad to let anyone use my stuff for training (some rights reserved), I thought I’d license my blog under creative commons. You can find the details at the bottom of this page (unless you’re reading through RSS).
It was pretty easy, in case you’re wondering, you can generate nifty html to license your stuff on CC’s site starting here.
I thought this post fitting considering the fact that some bloggers I follow (notably Jonathan Kehayias, and Brent Ozar) have talked about blog plagiarism lately. So I wanted to make it explicitly clear what’s okay with the content of this blog.

July 9, 2009

Top 10 SQL Server Connect Items by votes.

Filed under: Miscelleaneous SQL — Michael J. Swart @ 5:25 am

Taking a page from cracked.com or David Letterman. Everything seems to be easier to read if it’s in a top n list. I decided to search the Microsoft Connect site to list the most voted feedback items for SQL Server (past and present). Mostly to see what Microsoft has done with them.

10. 284192 Farsi Language Support:

Closed (Fixed) Suggestion. It’s supported with SQL Server 2008. This is a win for Microsoft (and Persian developers).

9. 331220 Backup / Restore without index data

Active Suggestion. It was opened March of 2008 and remains opened. It seems like a great suggestion to me. You sacrifice backup/restore speed for smaller space. The Microsoft response is less than satisfying. They’re saying: “That’s too haaaaaard” (I’m paraphrasing).

8. 125117 Need 64-bit JET provider for x64 box

Closed (External) Suggestion. I think external means that this is not a SQL Server issue but a MS Office issue. I imagine this one is so popular because it’s a component to a method that allows importing data from Excel sheets into SQL Server (via SSIS). Again Microsoft’s response seems like “Thanks for your feedback but no”

7. 127219 CREATE OR REPLACE

Active Suggestion. A suggestion that is in its fourth year. Do you remember School House Rock? Do you remember that bill is waiting to become a law? That must be what this connect issue is feeling. There are a lot of emotional reactions around this issue. Microsoft’s response to this issue is “We can’t implement everything!” (again I paraphrase). But this feature is certainly got to be a lot simpler than backups without index data (see #9 above). Also, Aaron Bertrand thinks that Microsoft is finally seriously considering it, so that’s promising.

6. 299296 Relax restriction that table parameters must be readonly when SPs call each other.

Active Suggestion. Erland Sommarskog opened this one; he’s an MVP who wrote – in my opinion – the definitive guide to Arrays and Lists. So he knows what he’s talking about. It would be a great feature and enable a really dynamic way to move data around while keeping to set-based principles. The suggestion was opened 12/10/2007. It was created as a response to Katmai details that were coming out about the new table-valued parameters feature. As such, it was a bit too late to consider this issue for 2008. But Microsoft does say that they have it “firmly in our radar to address as part of the next release” (direct quote this time)

5. 254293 Allow literals and read only table data to be represented as enums

Active Suggestion. I’m not sure what to think about this. It would allow syntax that has where clauses something like:

WHERE PaymentType IN (Mastercard, Visa)

The hardest part is to decide what to do with a collision of enum values and column names. Microsoft says there are some workarounds and they’ll consider it in the future. I don’t see the value in this feature. Well, I do, but not enough to get this issue on this top 10 list. Let me know what you think.

4. 124550 Bring back stored procedure debugger in SQL Server 2005

Closed (Fixed). Win for Microsoft (and debuggers)! You see that debugger that’s available in SQL 2008? You can thank this issue.

3. 124561 Make full scripting for tables as it is in SQL2000

Closed (Fixed). Call this a win for Microsoft. It is fixed, but many people were not satisfied with the fix. I think it’s just fine. There is a new Scripting page in Tools –> Options. On a related note, Paul Randal describes an obscure feature that lets you script data from tables here.

2. 341872 IntellliSense backward compatibility

Closed (By Design) Suggestion. A disappointment for me and many others. I’ve blogged about this before. Again Microsoft’s message seems to be “Thanks for your feedback, but no, that’s too haaaaard.” I paraphrase. What gets most people is that this used to work in one of the Katmai CTPs but they disabled it for RTM.

1. 326575 Release Service Pack 3 for SQL Server 2005

Closed (Fixed). I’m not sure, but isn’t this one like petitioning the sun to come up? I think SP3 was going to happen with or without the issue.

June 29, 2009

Going to PASS Summit this year!

Filed under: Miscelleaneous SQL — Michael J. Swart @ 9:29 am

I’m psyched! I plan to go to the PASS summit this fall in Seattle. I expect it to be time very well spent. (The word ‘psyched’, is that too 90s?) If I can get a couple hours to myself, I also plan to visit my favorite settings from the Twilight series.

No not really.

I plan to meet as many people as possible. If you’re attending and spot me looking bored (unlikely) introduce yourself.

January 23, 2009

Technical Interviews (good or bad?)

Filed under: Miscelleaneous SQL — Michael J. Swart @ 6:41 am

Recently there have been a couple articles I’ve read that give different sides to the argument over whether technical interviews are effective, valuable or worthwhile.

Brent Ozar in an article called Top 10 Interview Questions to Ask Senior DBAs mentions (as #2):

Anything to put them under stress … This is your one chance to see how they handle stress before the brown stuff actually hits the fan. Ideally, a senior DBA is someone who’s had their cage rattled more than once, and they’re comfortable under the gun.

With a different point of view, Phil Factor has an article titled Technical Interviews, and tests, have got to stop! He begins by saying:

… I’d like more successful developers to confess their inability to remember much more than their name under the pressure of a technical interview. The most extreme geeks all have brains that blue-screen with a temporary aphasia under stress.

Phil Factor then goes on to argue for a different (albeit unconventional) interview technique that measures determination. 

I have to side with Brent on this one for a few reasons:
Jobs are stressful. I don’t know of any IT job that is so cushy that the employee is not expected to work under pressure from time to time. It’s nice to see a candidate who has that grace under pressure. Confidence is the key I think. 
These questions are not like academic exams. Phil Factor’s assumption is that the only point of these technical questions are to see whether the candidate gets the right answer or not. 5 marks for getting the right answer! And perhaps some interviewers do treat questions that way. But better interviewers care as much (or more) about the candidate’s approach to problem solving and behaviour under stress. And I think Brent and Phil can both agree on that point.
Bias disclaimer: I love puzzles. I love challenges like that. So I’ve never had a fear of taking technical quizzes. In his article Brent posed the question of solving the FizzBuzz problem with SQL code. I stopped reading the article right there and solved it before returning to the article. (See problem as posed by Brent here) If asked about trivial stuff like which port SQL Server typically listens on for secure connections. I have no problem quickly saying “I don’t know that off the top of my head I’d have to look that up”
So I say yes! Good, keep the technical interviews coming!

Michael J. Swart

January 19, 2009

Sending Query Results to Colleagues

Filed under: Miscelleaneous SQL — Michael J. Swart @ 6:30 am

If I need to send data or query results to colleagues, I like to send them using Microsoft Excel Especially if it’s through email and the results aren’t so huge as to overwhelm the clipboard.
When doing this, there’s a couple things that I like to do to make my life easier:

First there’s an option that you might not have come across yet in management studio that includes the column names when copying the results. Under the Tools menu, select Options. The following dialog is shown:

Select Include column headers when copying or saving the results. This (as you might have guessed) saves some time when pasting into excel:


Update (Feb 5, 2009
): Interesting quirk about the above feature: Column headers aren’t included if there is only data from one column selected. Also this feature has no effect on existing query windows, only on newly opened windows. So without that knowledge, it might seem like this option has no effect.

The second thing I like to do is to include the query on Sheet 2 and format the results. I.e. formatting includes bolding the header, and enabling autofilter on the worksheet, etc…:
See an example (video).
It’s nice and it works. (But it’s not quite enough to justify it’s own Excel template). I think Excel does well for what it’s used for here: A portable, sortable, data viewer.

January 2, 2009

A Meta-Post (about Google Analytics)

Filed under: Miscelleaneous SQL — Michael J. Swart @ 6:34 am

That is, a blog post about blog posts. Specifically about Google Analytics.

For the past few months, I’ve found it interesting to use Google Analytics to see how people arrive at my blog. Most of the traffic comes from Google’s search page and from what I understand, that’s true of most blogs (or web sites in general). Here’s a couple interesting facts that surprised me:

  • The most common search term that generated visits to this blog is 341 characters long. 52 visits representing 6% of all visits since I started tracking. That search phrase is:

    a network-related or instance-specific error occurred while establishing a connection to sql server. the server was not found or was not accessible. verify that the instance name is correct and that sql server is configured to allow remote connections. (provider: named pipes provider, error: 40 – could not open a connection to sql server)

    And that phrase will bring you to this post.

  • The second most common search term at 3% is “sql poetry“. No joke.

For those that use Google Analytics. Leave a comment about any surprises you may have found yourself.

December 16, 2008

My Security Blunder

Filed under: Miscelleaneous SQL — Michael J. Swart @ 2:07 pm

A nice story for the holidays.

Not too long ago I made a small error that was going to cause me to lose a number of hours of work and the headache that goes along with it. Okay, if I’m being honest it was more than a small error; it was a huge snafu! And although the only affected systems were my own development box. I still had that sinking feeling in my stomach the moment I realized my situation.

My blunder

On my development server I have SQL Server 2008 installed and I was poking around and playing with some of the more general security features. I wanted to find out what different users could do when granted various privileges. And so as part of this poking around, I granted myself (DOMAIN\MSWART) access to the server and I disabled the BUILTIN\Administrators principal.

Then after more poking, I wanted to remove my Network Service account from the set of logins. Now since the Network Service account uses my computer’s credentials, the login was called (DOMAIN\MSWART$).

You might see where this is going. I forgot the ‘$’ symbol and wound up removing any rights that I had on the machine.

What this meant for me

Luckily this was a development server and any data I cared about was backed up. The real kicker is that I had no way of accessing the database server. To me it looked like this meant going through the process of reinstalling SQL Server which is easier said than done. See Euan Garden’s experience here and Victor Hurdugaci’s experience here.

What I ended up doing instead

But guess what. Management Studio was still open and I hadn’t refreshed Object Explorer so I could still see the list of principals for my server. There was still one login that had access: NT AUTHORITY\LOCAL SERVICE.

Well what else was there to do? I created a windows service. On startup for the service, I used ADO.Net to read from a temporary text file and execute the contents on my database.

I installed the service using InstallUtil.exe I ran a couple scripts a few times (checking and reading any errors in the Event Log). After a few trials I attempted to add DOMAIN\MSWART back as an admin…

And it worked!

I was in! I could do anything I needed to do again. The whole ordeal cost me about twenty minutes (or it saved me three and a half hours if you’re the glass-is-half-full kind of person)

What did I learn?

Don’t do that… for starters. I also found out that if a service can access your database, then so can anyone who has a decent amount of control over the computer.

And from another point of view, I learned how to write quick and dirty windows services.

Update! (Jan 2, 2009)

Joe Sack pointed out (via Jason Massie’s blog here) that I could have more easily gained access by restarting the SQL Server service with the -m or -f options to put SQL Server in single user mode. Details at Microsoft’s troubleshooting page: Troubleshooting: Connecting to SQL Server When System Administrators Are Locked Out

« Newer PostsOlder Posts »

Powered by WordPress