Archive | March, 2011

To Do: Win Great SQL Training and a Cruise

Wondering what to do when you get a break from work email today?

Make your opening move in a fun contest.

What’s to win?

The prize is tempting booty: Idera Software is giving away a free trip to SQLCruise Alaska. And not just part of the trip, it’s the full meal deal: a 7-day cruise for two from Seattle to Alaska (departs from Seattle, WA on May 29th, 2011, returns June 5th, 2011), one seat in the SQLCruise training taking place aboard the cruise, and airfare for two to Seattle (up to $1,500).

Wow. Did you notice that “cruise for two” and “airfare for two” part? You get the training AND you get to take along a friend or loved one. Pretty rad.

The agenda’s been posted for the cruise— it’s going to be unique and amazing. The cruise is full of great technical content and training to build your skills and work with you to find practical changes to improve your work environment. I love how the agenda is laid out to change up the pace and keep everyone thinking and learning.

Check out the awesome training on the Alaska SQLCruise here.

How to enter

Head on over to the contest forum, which also has all the official rules for entry.

There’s a quick registration step (it’s painless, I did it myself), and then here’s how you enter:

  • Tell us about your SQL victory. Post an entry describing what horrid SQL beast you encountered and how you vanquished it.
  • Post a picture of yourself looking victorious (extra credit for Viking helmets and/or attire)
  • Include the phrase “I VANQUISHED THE BEAST!” in your entry.
  • Share your submission with your friends.

Worried you might submit now and come up with a better idea later? It’s ok, you can enter more than once, and each entry will be judged individually. There’s no reason not to dive in now.

Tell your story

Getting fitted for my judge's wig

I love this contest because it’s about STORIES, and it’s open to everyone with a story to tell.

Tell a story about your victory. There’s so many people out there in the SQL community who have great passion and do so much. There’s so many of you who love to write and share your experiences.

Think about the things you’ve done to save the day– in the office, on the forums, maybe even on… Twitter???

I’m a judge!

I’m honored to be one of five judges for the event. I look forward to reading about your SQL Victories– let’s hear it!

Comments { 0 }

I laughed, I cried, it was better than CATS: The Fast Track Data Warehouse 3.0 Reference Guide

Careful what you say about cats, lady.

You know what’s crazy?

A comprehensive, technical, well thought-out, and ENJOYABLE document. One written with the occasional interesting diagram and a reasonable use of acronyms, with effective tables and practical advice. A document that’s written for a human being which has helpful links to supporting documentation, but still makes you think.

Don’t get me wrong– a lot of people write very good documentation. And Microsoft publishes a really large volume of helpful information.

It’s just remarkable when you find great documentation that is technical, covers a lot of ground, and yet is very readable.

But I found some! It’s the Fast Track Data Warehouse 3.0 reference guide.

But I don’t have a Fast Track Data Warehouse…

Doesn’t matter, it’s still a really good read. You should read this document if:

  • You are interested in SQL Server
  • You are interested in Data Warehouses
  • You are interested in technical writing

Along the way, this document talks about everything from categorizing workloads, startup options for data warehouses, Resource Governor, creating and configuring filegroups and managing fragmentation, determining optimal table structure, statistics, compression, loading data, benchmarking, and validation. That’s a lot of ground, and a lot of it is useful to think about for a wide variety of systems.

Example: I came across this document while searching for specific use cases for a partitioned heap. The document talks about considerations for large partitioned objects in data warehouses, and when a partitioned heap might be appropriate vs a partitioned table with a clustered index– it does it quickly, neatly, and thoughtfully.

The most interesting thing

This isn’t a sales document, but it makes me want a Fast Track Data Warehouse.

It makes me feel like a Fast Track system is for smart people– after all, smart people took a whole lot of time to write this doc. It just FEELS smart.

To me, that’s really impressive– if I can write a little bit more like that every day, I’m moving in the right direction.

DISCLAIMER: the title to this post does NOT refer to the SQL CAT team, who produce some pretty freaking amazing documents. Instead, it refers to free range clip-art cats, which may or may not have pianos pictured as falling on them in my slide decks. And possibly a Broadway musical which I never saw. And probably to SNL.

Comments { 3 }

There’s more than one way to skin an eggplant: Using APPLY for calculations

Choices, choices

Here’s a little TSQL snack. I picked this up in a presentation by Itzik Ben-Gan at the PNWSQL user group recently, and it’s become a fast favorite.

CROSS APPLY and OUTER APPLY- another use

The APPLY operator is perhaps more flexible than  you think. You may already know that you can use it to inline a function, or to replace a join.

But wait, there’s more! You can also use APPLY to perform calculations and simplify your query syntax– this is because the APPLY operator allows you to  express a calculation that can be referred to:

  • in further joins (which may or may not use APPLY)
  • by columns
  • in the where clause
  • in the group by

This is really helpful, because you can’t refer to the results of a computation in one column from anywhere but the ORDER BY.  This is because of the order of evaluation of parts of the statement.

I know this sounds confusing. It’ll make more sense in an example.

A sample query– the ‘before’ version

Here is a query written for the AdventureWorks sample database. There’s all sorts of examples that are possible for this, but I decided to go with one grouping data by month, using my favorite formula to round dates.

It shows the total quantity of orders by Product for an entire order month, for orders placed on or after 2004-07-01.

SELECT  DATEADD(MM, DATEDIFF(MM, 0, oh.OrderDate), 0) AS OrderDateMonth,
        p.Name AS ProductName,
        SUM(orderQty) AS totalQuantity
FROM    sales.SalesOrderHeader oh
JOIN    Sales.SalesOrderDetail od
        ON oh.SalesOrderID = od.SalesOrderID
JOIN    production.Product p
        ON od.ProductID = p.ProductID
WHERE   oh.OrderDate >= '2004-07-01'
GROUP BY DATEADD(MM, DATEDIFF(MM, 0, oh.OrderDate), 0),
        p.Name
ORDER BY OrderDateMonth,
        p.Name

Notice that to group the date at the month level, we need to include the calculation in the column in the column list, as well as in the group by clause.

The query rewritten using APPLY for the calculation

This can be rewritten with CROSS apply to move the calculation into the JOIN area and only specify it once.

The benefits: this will simplify your syntax and reduce the chance of typos and errors, particularly when you need to go in and change the calculation. In cases when you’re displaying a sum in one column and showing a percentage using it in another column, this trick is *fantastic*. (Query numbers from the DMVs a lot? you’ll love this.)

Here, the calculation on the date is moved into the cross apply. It can be referenced as oh1.OrderDateMonth in both the list of columns, and in the GROUP BY portion of the query without rewriting the calculation.

SELECT  oh1.OrderDateMonth,
        p.Name AS ProductName,
        SUM(orderQty) AS totalQuantity
FROM    sales.SalesOrderHeader oh
CROSS APPLY ( SELECT    DATEADD(MM, DATEDIFF(MM, 0, oh.OrderDate), 0) AS OrderDateMonth ) AS oh1
JOIN    Sales.SalesOrderDetail od
        ON oh.SalesOrderID = od.SalesOrderID
JOIN    production.Product p
        ON od.ProductID = p.ProductID
WHERE   oh.OrderDate >= '2004-07-01'
GROUP BY oh1.OrderDateMonth,
        p.Name
ORDER BY OrderDateMonth,
        p.Name

What does the execution plan look like?

Click for a larger image

The execution plan for these two queries are identical.

In this case, the optimizer looks at these two queries and realizes the activities it needs to do will be the same.

Other options

You can create further CROSS APPLY or OUTER APPLY joins that refer to computations in prior joins.

You can also refer to the resulting computation in the where clause.

But be careful….

As with anything, you want to make sure you’re getting a good execution plan, and not shooting yourself in the foot with a new trick.

One big area to watch: although you can refer to these computations conveniently in the WHERE clause, you still want to be careful you’re using appropriate criteria.

For instance, if we were to change the example above to refer to the result from the CROSS APPLY oh1 in the where clause like this:

SELECT  oh1.OrderDateMonth ,
        p.Name AS ProductName ,
        SUM(orderQty) AS totalQuantity
FROM    sales.SalesOrderHeader oh
CROSS APPLY ( SELECT    DATEADD(MM, DATEDIFF(MM, 0, oh.OrderDate), 0) AS OrderDateMonth ) AS oh1
JOIN    Sales.SalesOrderDetail od
        ON oh.SalesOrderID = od.SalesOrderID
JOIN    production.Product p
        ON od.ProductID = p.ProductID
WHERE   oh1.OrderDateMonth >= '2004-07-01'  ---Don't do this!
GROUP BY oh1.OrderDateMonth ,
        p.Name
ORDER BY OrderDateMonth ,
        p.Name

… then in this case the query would not be able to use an index on OrderDate on the sales.SalesOrderHeader table, if one exists.

This is not specifically because of the CROSS APPLY, but because we are forcing SQL Server to apply the functions to every value to identify if it satisfies the criteria. That prevents a seek.

Comments { 3 }

Meeting Up for Data and Waffles: Are you with me?

If the waffle is like the data storage structure, what's the butter?

I’ve been thinking about this for a while, but the idea started to really take shape yesterday.

After a bit of chat on Twitter, I asked some of my local friends what they think in email– and sounds like this may be a good idea. Check it out and please tell me your opinion in the comments!

The mission

Instigate interesting discussions, develop presentation skills for technologists, foster problem solving. Have fun while doing it. Eat waffles.

The idea

Meet with people interested in working with data for really good nerdy conversation and some breakfasty foods. I’d like this to be a place for new presenters to start speaking AND for experienced speakers to try out new topics, or test new methods of conveying ideas. (Demos, labs, games, exercises, etc.)

I’m most familiar with the SQL Server community in Seattle and I think that community would really take to a regular event like this. People who work with other technologies who are interested in working with data would also be very welcome.

The format

Structured, but flexible. Each meeting would be planned, but different.

The basic ingredients will typically be lightning talks and short presentations. However, we can customize each meeting to be unique and follow people’s interest. The core ideas are:

  • Nothing is required to be finished or polished. Total first drafts are OK. Finished works are also perfectly OK.
  • Be respectful to the speaker (unless the speaker requests otherwise– ie practice working with a difficult questioner, etc)
  • People can choose if they want feedback or not, either on speaking or the technical bits, or both.
  • Working on less structured talks is OK, too– for example, bringing an interesting problem, asking questions, and talking through the problem with the group for 10 minutes.
  • Need a brainstorming session? Suggest the area you’d like to brainstorm as your topic.

Structure

  • Everything is free and open to the public.
  • “Meeting” time will be 60 minutes, with time set aside before and after for waffles and discussion.
  • Meeting topics will be submitted and posted ahead of time so people can attend based on interest.
  • All topics regarding data, administration, and development working with data are fair game.

I imagine we’ll have at least 15 minutes of general geeky discussion and Q&A at the end– maybe have some goofy game choosing topics or trivia sometimes if people are up for it.

I really like the idea of having each meeting be a little different based on what people are thinking about and working on. This should develop pretty organically.

Frequency

Once per month, Saturday at 11am.

Possible location

There may be other options for this (exciting!), but the location will likely be in the city of Seattle.

One option looks like the Cortona Cafe. Is this a place you would travel to on a weekend morning?

Is this a ‘real’ user group?

Nope. We have a great SQL Server community in the Seattle area, and a fantastic SQL PASS User Group, and I’m not looking to replace that.  Instead, I think we have  enough creative people interested in working with data to start a separate group that’s focused on generating ideas and trying out new things.  This may be working on new ideas with technology, or growing in the presenting or communicating area of your career working with data.

If there’s interest in meeting monthly we may do that. If we have a core group of people who’d like to get together quarterly, that’s cool too. The idea is to try it and see how it develops.

My questions for you…

  1. Does this sound like something you’d like to attend?
  2. Any suggestions?
  3. Is having this on the weekend a good thing, or a bad thing?
  4. Have  you tried something like this before? What was your experience like?

Did you notice?

There are actual WAFFLES for purchase at the Cortona Cafe, people. WAFFLES!

But even if there are no actual waffles at every event, wherever we land, I think they may remain in the title.

Comments { 10 }

Dynamic Management Quickie: Exploring SQL Server’s system views and functions as you work

Note: If you like this post, here’s one you’re going to like even better! Check out DMV/DMF Info Just A Couple Clicks Away by Brad Schultz.

There’s a lot of dynamic management and system objects to keep track of in SQL Server.

We all sometimes have the moment when we can’t remember exactly which DMV, DMF or other system view/function returns a particular column, or if something even IS accessible from the system objects.

When this happens, remember that it’s easy to query system object and column names. Sys.system_columns and sys.system_objects are here to help.

Exploring the system views and functions yourself will also help you find new things.

This example shows all the system views and functions which are likely to have to do with CPU:

SELECT
SCHEMA_NAME(SCHEMA_ID)+ '.' + o.Name AS SysObjName,
o.type_desc,
c.name AS ColumnName
FROM sys.system_columns c
INNER JOIN sys.system_objects o ON o.object_id=c.object_id
WHERE c.name LIKE '%cpu%'

I like to use this version of the query, which includes the URL to look up more about the DMV. I like to use the browser in SSMS itself to look these up, so I include the shortcut for that in the header.

SELECT
	SCHEMA_NAME(SCHEMA_ID)+ '.' + o.Name AS SysObjName,
	o.type_desc,
	c.name AS ColumnName,
	'http://social.msdn.microsoft.com/Search/en-US/?Refinement=117&Query=' + SCHEMA_NAME(SCHEMA_ID)+ '.' + o.Name AS [Help! Ctrl + ALT + R to open web browser in SSMS]
FROM sys.system_columns c
INNER JOIN sys.system_objects o ON o.object_id=c.object_id
WHERE c.name LIKE '%page%'

The output looks like this (click for a larger view):

I’ve started using this lately since it helps me explore as well as remember.

Just when you think you know everything about the system objects, you’ll find something new.

Fun example: look at all the columns like ‘%page%’.

Comments { 8 }

I’ve gone magazine

I’ve rolled out some changes to my blog– I’m using a “magazine” format now.

What do you think?

Do I look good in this blog? (I think makes me look taller.)

If you’re subscribing to my RSS feed, things should look pretty much the same. But I’d love it if you clicked through and told me what you think of the new format.

Why the change?

I’d like to post more frequently, including shorter posts with bits of information: the new format will help support that by displaying more posts on the page.

I am my blog

The more time I spent writing about technology, the more I feel like I come through on my blog as who I am. After a couple of years writing this, blogging is part of my life and I would miss it if I stopped. It’s gotten to the point where I sometimes like to buy my blog presents and dress it up in new clothes. At least I haven’t tried to take it to dinner yet.

Why blog?

Barry Ritholltz wrote down what he thinks are good reasons to blog. All ten of those good reasons resonate with me– so here’s to blogs, mine and yours.

“If my doctor told me I had only six minutes to live, I wouldn’t brood. I’d type a little faster.” …Isaac Asimov

Update: I’m still really pleased with the magazine format on the Woo Canvas theme a few weeks later. There was only one thing that bothered me– the theme showed all excerpts, and I wanted to show full posts for the 4 most recent posts. Found the resolution in the forums:

Open template-magazine.php and change line 64

<!--?php the_excerpt(); ?--> 

to

<!--?php the_content(); ?--> 
Comments { 8 }

24 Hours of Rad: 24HOP Spring 2011 Recap

This past Tuesday and Wednesday (March 15-16) were 24Hours of SQL PASS.

On Tuesday I presented my talk, “No More Bad Dates: Best Practices Using Temporal Data.” It was tons of fun to give, and afterward I was so happy to see that I’d gotten mad love from the SQL Twitterverse.

You guys make me feel awesome. And even more than that, you make me want to research and write a hundred presentations.

Y’all Made Me Promise: Watch this Space for the No More Bad Dates Poster

In the Q & A for the talk, you requested that I provide a sample cheat sheet. I’m plugging in my electronic pen and I hereby promise to roll one of those out to you in the form of a custom poster.

Keep watching this space, it’ll be here soon. (I have a couple technical blog posts I am ITCHING to write. And itching isn’t fun, people.)

Check Me Out In Reruns

Recordings of presentations will be available in about a month. In the meantime, if you’d like to you can download my slide deckContinue Reading →

Comments { 3 }

Be My Date Next Tuesday, March 15 at 24 Hours of PASS

SQL Server Pickup Lines Not Included

Next week the Professional Association for SQL Server will be providing 24 hours of free, online training on SQL Server.

Come get your learn on.

Register Now!

My talk will be next Tuesday, March 15 at 10 AM Pacific / 1 PM Eastern / 5 PM GMT.

It is Session 06: No More Bad Dates: Using Temporal Data Wisely.

Register for sessions here. There are many great sessions on Tuesday and Wednesday– pick what fits you, and you’ll receive a calendar invite with a link to the LiveMeeting for each one. (Timezones are listed in GMT, which can be confusing for the people of North America, particularly since Daylight Savings is coming to some of us this weekend. The calendar invites will help, I promise!)

My session is on best practices for choosing date and time types in schema, with lots of tips for writing queries working with dates and times.

Why are Dates Interesting? How Will This Talk Help YOU?

I love the talk I’m giving on dates and times because I get to cut across different areas– I get to talk about data types, choices in schema design, and how to write T-SQL. I also get to talk about little-known features of SQL Server, and give lots of tips and tricks along the way.

Working on this presentation has been a really fun journey. It began when I noticed in Books Online that the datetime data type is officially no longer recommended for new development– and this has been the case for three years!

This is rarely discussed and, except for DATE, the new types are rarely used. So I began to ask the question: is it ever worth converting existing schemas to the new types? Is there any reason to still use older types, such as SMALLDATETIME? What do you sacrifice if you don’t use the new DATETIME2 type, and are there any issues if you start using it? What are the most common, but least known problems when working with dates?

Dates aren’t as Simple As We Think. I’ve got Answers, and Practical Advice.

It’s fun to give practical, useful advice. I recently gave this talk at SQL Saturday #65 in Vancouver, BC, and had a great audience. I asked them to share with me whether they learned anything new, or were surprised by what I covered.

I heard back from more than ten people in the audience in person or by email, and all but one said they learned something new. Everyone had worked with date and time types before. They were also great at letting me know which topics could use a little more detail and clarity.

Most people commented that they were surprised by the talk, and that things are trickier than they’d understood.

Comments { 1 }