Where in the world are Jen and Sean?

Always having fun with tech
Always having fun with tech

Updated with more SQL Saturdays!

Well hi there, folks. A month slips by so very fast.

Here is your January report on what we’re up to, and where we’re going to be in the near future. What are we up to? Minion, of course! Also, Minion, and some Minion. In our spare time, we Minion. (The latest update to our upcoming Minion Enterprise release is the auto-scripting of SQL Agent jobs. Awww, yissss.)

Done: THIS VERY WEEKEND we will be speaking and sponsoring SQL Saturday Austin. So if you like free training and SQL enthusiasts, head out. Be sure to drop by our booth, get stickers, and talk ME!

The schedule so far:

We’re looking at adding more dates and more precons. If you’d like to see us at your event – precon, speaking, and/or sponsoring – let us know on Twitter or in email, kay?

And if you’re not hitting any of these, pick your own SQL Saturday!

Fun with Operator Precedence

Let’s have some fun with operator precedence today. Specifically, logical operator precedence.

Specifically, how is it evaluated when your where clause says “WHERE This AND That OR Something AND that”, without any clarifying parenthesis?

Let’s play around with this. The simplest test scenario is a SELECT 1. If I get a 1 back, that means my WHERE clause evaluated to true, right? Right.

So this will definitely return a 1:   SELECT 1 WHERE 1=1;
And this won’t:   SELECT 1 WHERE 1=2;

This will also return a 1:   SELECT 1 WHERE 1=1 and 2=2;
And this won’t:   SELECT 1 WHERE 1=2 or 2=1;

Query 1

But here’s the fun part. What if I open up a query that looks like this:

SELECT 1
WHERE 1 = 1
   AND 2 = 1
   AND 1 = 1
   OR 1 = 1
   AND 2 = 1;

How does THAT evaluate? Well we need to glance at the operator precedence chart to see what SQL Server evaluates first. We’re concerned here with AND vs. OR…and it turns out that AND is evaluated first.  So, we can visualize – and indeed, clarify – the query above with the judicious use of parentheses:

SELECT 1
WHERE 
   (1 = 1
   AND 2 = 1
   AND 1 = 1)
   OR 
   (1 = 1
   AND 2 = 1);

(Note, by the way, that parentheses are actually operators in their own right. MSDN says: “Use parentheses to override the defined precedence of the operators in an expression. Everything within the parentheses is evaluated first to yield a single value before that value can be used by any operator outside the parentheses.” Here though, we’re using them not to override precedence, but to highligh which parts SQL is evaluating first.)

So that first parenthetical set: (1=1 and 2=1 and 1=1) obviously evaluates to FALSE. The second set ALSO evaluates to false (1=1 AND 2=1). We could translate it to this pseudocode:

SELECT 1
WHERE 
   (this evaluates false)
   OR 
   (this evaluates false);

So, this query would not get us our SELECT 1.

Query 2

But this query would:

SELECT 1
WHERE 1 = 1
   AND 2 = 1
   AND 1 = 1
   OR 1 = 1
   OR 1 = 1
   AND 2 = 1
   OR 1 = 1;

Why? Let’s sort it out visually again, using parentheses. Remember, all of the ANDs get evaluated first, so let’s group those with parentheses:

SELECT 1
WHERE 
   (1 = 1
   AND 2 = 1
   AND 1 = 1)
   OR 1 = 1
   OR 
   (1 = 1
   AND 2 = 1);

Ah, there it is. All of those ANDs get sorted out first, and then the ORs are considered. Or to write it in pseudocode:

SELECT 1
WHERE 
   (this evaluates false)
   OR this evaluates true
   OR 
   (this evaluates false);

Your friend, the parenthesis

All of this playing with parentheses so far has just been for visual aid.  But as we noted before, parenthesis are actually ironclad rulemakers in their own right. You can use parentheses to force the evaluation order that you want, so that this does NOT return a 1:

SELECT  1
WHERE   1 = 1
        AND 2 = 1
        AND ( 1 = 1
              OR 1 = 1
              OR ( 1 = 1
                   AND 2 = 1
                 )
              OR 1 = 1
            );

…even though, without the parentheses, it’s just Query 2 all over again. The parenthesis forces SQL to evaluate the query thusly:

SELECT  1
WHERE   evaluates to true
        AND evaluates to false
        AND ( evaluates to true
            );

Go on, play with a few simple examples yourself. See how it all fits together.

Happy days,
Jen McCown
http://www.MidnightDBA.com/Jen

 

A year long blog

Tuesday, February 17

Wil Wheaton’s Radio Free Burrito is back on the air, and it always gets me in a creative frame of mind. Thus, the (nearly) year long blog, where I will write regularly whenever I remember to. I’ve set this to auto-publish on December 17, 2015.

Today’s project is a personal one, ish. I grabbed a script off of TechNet and modified it to pull the sizes of ALL files on my hard drive into SQL Server, where I can group by either extension or root path (e.g., C:\temp\) to see WHERE THE HELL ALL MY FREE SPACE HAS GONE.  Seriously, 220GB all eaten up and I can’t find out where it’s gone. (Answer: Everywhere. But I did make some space by archiving off videos and pictures, and deleting duplicate files and old applications.)

Just past: SQL Saturday Austin and Albuquerque, and Allan Hirt in studio for DBAs@Midnight. Upcoming: SQLBits in London.

Friday, March 6

We’re at SQLBits in London. Our precon went well, or so we keep hearing. We have one regular session down, and two more to go. It’s been a wonderful time so far, and we’re really looking forward to speaking in Cardiff and Exeter user groups next week.

If you’re in London, required eating includes: fish and chips, beef and ale pie, mushy peas, and a good curry.

Wednesday, May 20

We’re in “finals week” for the Minion Backup release (technically, finals week is 2 weeks long). And I’m enjoying the guts out of this process, but we’re just so BUSY. I’m taking a break, in fact, from finishing what is surely going to be a 130 page product document, in order to write a blog post about this awesome feature I just documented.

In the last couple of months, we’ve released Minion Enterprise, started our new company MinionWare (our designer is working up a logo idea right now, and it’s fantastic!), been down to Houston for a UG meeting. Our boys have fallen in love with Doctor Who (the show, not the guy), and the daughter’s made honor roll. And, it’s apparently monsoon season here in Texas.

Now, back to it!

Wednesday, June 17, 2015

Busy times. Minion Backup 1.0 is out on our new MinionWare website. One or both of us (sometimes with kids) have been to Baton Rouge user group, Oklahoma City user group, SQL Saturday New York, and SQL Saturday Houston. All good times. The daughter wants to take her driving test, and we’re just trying to find the time.

We’ve got a booth reserved at the PASS Summit, and just found out that we’re going to give our Enterprise Scripting precon at the Summit too! Verra verra cool.

And it’s monsoon season again. The cooler air is wonderful, though those with flooding issues might not appreciate it so much.

Tuesday, July 28, 2015

Man, I WISH it were monsoon season right now. We get a break on Thursday; it’ll be overcast and only 99F (37C)! This is quite a contrast to our lovely Seattle vacation earlier this month. I ran the #SQLLongRun route while I was there. Hilly, but lovely.

We released Minion Enterprise 2.1 last week. It’s got the AD expansion in, and the index research module, and so much more. And we really improved the testing process this time around. I kind of wish we had another release sometimes soon; I enjoyed updating the test harness that much.

Next up, SQL Saturday Baton Rouge (with precon), and eventually the start of DBAs@Midnight again.

Monday, September 21, 2015

Well. We’re back on the air with DBAs@Midnight (season 7, wow), and I’m in love with the new, sitcom-style intro.  And unrelatedly, my old laptop died and I had to get a new one. Stop smirking…I liked my old laptop. This new yoga is okay, but it’s got graphics issues, and they TOOK AWAY THE FUNCTION KEYS off of the keyboard. Seriously, Lenovo, what is your problem?

And yesterday we took our youngest Junior MidnightDBA out to San Diego for our first SQL Saturday as a vendor. That was kind of fun! We talked to a lot of people, and gave away a Kindle Fire 6. Then we took the kid swimming and hanging out at Balboa park.

Next up is my half marathon, which is nearly overshadowed with how excited I am to start training for the Dallas marathon. And of course, preparing for PASS Summit in five weeks. Who, me? Busy?

Wednesday, October 7, 2015

Gah…3 weeks till PASS….too much to do…gah…

On the plus side, our Halloween costumes are all sorted. The boys are being monsters from Doctor Who, and I’m River Song!

Wednesday, November 25, 2015

Well that month and a half went fast. We were sponsors and exhibitors and speakers at PASS Summit, and the precon went really well. We got home just in time for trick-or-treating. The airline lost one piece of luggage and then found it.

More recently, we saw The Martian (amazing), and we took a day to binge-watch the new Netflix series Jessica Jones (by Marvel); not family friendly, but simply dark and amazing.  And, I watched the final movie of the Hunger Games series. They did pretty well, but the books will of course be my go-to for the story.

This week’s topic is PASS’s reminder of the anti-harassment policy. There has been much discussion and blogging.

The Dallas Marathon is 3 weeks away, and I’m so not ready for it. I had a muscle strain several weeks ago that messed up my training schedule. It’s okay, I’ll finish in about the same (or slightly less) time as last year – slow, but doable.

Thanksgiving is tomorrow! Sometime today I need to make a couple of pie crusts, and prepare the Parker House Rolls stuff.

Monday, December 14, 2015

I ran (well, ran/walked) the Dallas Marathon yesterday. It went pretty well, though even slower than last year. Next year I’ll try maybe not injuring myself, so that I can finish training. Yeah.

It’s been a busy year, by the look of this blog. We traveled a lot, and worked on Minion a lot, and ate pretty well. (Thanksgiving was absolutely the bomb.) Sean and I both had exercise related injuries – he was on crutches for part of the Summit – but everybody managed to stay out of the hospital, so there’s a win.

Next year is shaping up to look a good deal like 2015: lots of travel, lots of Minion work, lots of good food. Busy times. Maybe we’ll lay off a little bit for a  couple of weeks over the holidays…you know, as a rest.

Real news, real tech.