Tag awesome

What I’ve Learned at PASS

So, there’s this contest going on. So, what’s the contest? Write the best thing you’ve learned at a previous PASS conference and you could win a free registration or free hotel stay at PASS Summit 2009!

I went to my first PASS Summit many many months ago in November of 2008. I didn’t know many people in the SQL Server community, but I knew a few people. Throughout the PASS Summit, I spent time getting to know people. I met a lot of great people at the Summit and I’ve stayed in touch and become friends with many of them.

But, the best thing I learned at PASS was that there’s always something to learn from everyone. We’re all part of a community and we get better by learning from each other.

See? It’s just that easy! You could win a free registration to PASS. I could win a free registration. Maybe we both could win a free registration and meet at PASS and hang out!

Links for the Week 2009.06.05

Important Note: These are yesterday’s links. Not today’s. That’s why the date is wrong.

SQL Server

Really Search Cache for Execution Plans Jason Strate revists his code that finds the last plan that was used for a procedure.

Reasons for NOT using Varchar(MAX) Pat Wright brings back the argument of why you should or shouldn’t use varchar(max). You can clearly tell from the title how he feels. I’m quoted in this one, so you probably know how I feel. Read it. Learn it. Love it. SQL! (Yes, I know I said ‘field’ instead of ‘column’. Bite me.)

Development

Fighting technical deb with the wall of pain Technical debt is an insidious foe. Technical debt is that extra effort you need for future development because you made a quick and dirty design choice at some point in the past. This crap is poison.

Coding like it’s 1999 Cameron Moll put together a great overview of why he’s moved back to using the HTML 4.01 DOCTYPE. Just don’t use tables, okay folks?

Poor man’s guide to database optimization – by the Marquis de Sade Ever wonder if your code is being really crappy and executing N+1 selects for everything in a collection? WONDER NO MORE! With Ayende’s newest bit of code wizardry you can have a configurable wait time between each query executed. All of a sudden, you too will be dropped into your DBA’s nightmares as you realize that some programmer’s horrible, horrible code is slowly destroying the database!

Stuff & Things

Calvinball Projects Calvinball is the greatest game ever. Running a project like it’s a game of Calvinball has to be fun, right?

Feng Shui On Steroids: Design Your Space to Achieve Your Goals Jonathan Mead writes about how to use your environment to influence your ability to meet your goals. This looks like a great way to go about hacking my workspace and make it easier to get myself into a working mindset.

Lifehacker Pack 2009: Our List of Essential Free Windows Downloads Free software. Good stuff in here. Get it.

Links (6/4/2009) Steve PIetrek’s list o’ links from earlier this week has some gems in it, especially for software developers.

How to Lose Weight by Eating More Everything in here is true. “Diets” suck. They don’t work forever. There are good ideas in here on how to change the way you eat to be healthier.

This is MY Island

Jason Massie (twitter) has tagged me in the most recent DBA chain letter. Tim Ford tagged him, and here we are.

So, let’s recap, shall we?

So You’re On A Deserted Island With WiFi and you’re still on the clock at work. Okay, so not a very good situational exercise here, but let’s roll with it; we’ll call it a virtual deserted island. Perhaps what I should simply ask is if you had a month without any walk-up work, no projects due, no performance issues that require you to devote time from anything other than a wishlist of items you’ve been wanting to get accomplished at work but keep getting pulled away from I ask this question: what would be the top items that would get your attention?

There are a few things that have been on my plate recently.

Development

I’m not going to lie – I want to do a little bit of programming now and then. The CLR contains some phenomenal features that can be leveraged both inside and outside of the database. As a consultant and database developer, it’s incredibly important that I stay up to speed on techniques to access the database. Why? Different technologies have different paradigms and idiosyncrasies. It’s important to understand how developers are interacting with data so you can steer them towards the appropriate data access methodologies for their particular technology stack/platform. Different data access methods also have different performance profiles. It’s important to understand how LINQ to SQL performs in relation to NHibernate and why you might want to use it.

Plus, I really want to get my brain wrapped around NHibernate because it looks like an easy and powerful way to model data.

TSQL and the Storage Engine

I’m currently reading Itzik Ben-Gan’s amazing book: Inside Microsoft® SQL Server® 2008: T-SQL Querying. I would love to have the time to dive into this and read it a few times and experiment with the knowledge and techniques contained within its covers. Why? Part of what I do is tune SQL Server to run very fast. Part of making SQL Server run very fast is knowing how to write very fast queries.

The next book on my reading list is Kalen Delaney’s book: Microsoft® SQL Server® 2008 Internals (Pro – Developer). Like Itzik’s book, this contains a lot of information that I’m itching to get a hold of. I know a bit about the query engine and it fascinates me. I would love to sit down and carefully devote my time to studying how it works and how I can take advantage of its inner workings to make my queries run fast.

Data Mining

Like Brent Ozar, I really want to wrap my brain around data mining and dig into it. There is phenomenal knowledge and power hidden inside of data.

Let’s say you run a restaurant. You don’t know where your customers come from, but you know on any given Friday night you have the restaurant about 80% full, on average, all night. You advertise in the local paper that’s handed out in the area. You’re successful. This is good.

What if I could tell you the following about your average customer:

  • 35-44 years old
  • male
  • spends an average of $48
  • tips an average of 18%
  • lives 12 miles away in zip code 43004
  • likes pie

Of course, if I could cross reference this with an even larger body of data, I could probably determine where this average customer is most likely to shop, how much he spends, and what kinds of mass media he’s most likely to pay attention to, etc. Suddenly you know where to spend your money, you know who to target, and you have a better idea of how to appeal to your best customers. This kind of information, as Brent mentioned, is money. Giant filthy piles of money.

Who is next in this horrible glorious chain letter?

  • Jonathan Kehayias – SQL CLR maste rand builder of clusters
  • Tim Beinninghoff – bug enthusiast, PowerShell student, fighter of good fights, and all around good guy.
  • Rick Kierner – a filthy developer, coworker, and good friend.

Changing SSMS and Visual Studio Default Project Location

Changing the location of the default projects folder in Visual Studio is super easy to do. Just click the Tools menu, choose Options, and then select the Projects and Solutions tab to change the default projects folder location:

Changing default projects is fun!

Changing default projects is fun!

Sadly, this doesn’t change anything for SSMS. Why? I don’t know.

However, I do know how to change this in SSMS. Well, google told me.

  1. Open up your favorite text editor.
  2. Navigate to My Documents\SQL Server Management Studio\Settings
  3. Open up the .vssettings file in there. On my computer it was CurrentSettings-2009-05-24
  4. Search for the text “ProjectsLocation”
  5. You want to find a section that looks like <PropertyValue name="ProjectsLocation">%vsspv_visualstudio_dir%\Projects</PropertyValue> and go ahead and change the text value of that XML element to whatever you want it to be. (I chose C:\Projects!)
  6. ???
  7. Code

CBusPASS Meeting – June 11th

Is it nearing the second Thursday of the month already? That must mean it’s time to announce the meeting topic for CBusPASS!

This time around Brent Ozar and I will be talking about SQL Server Express Edition in a presentation titled “Developing Something for Nothing”

The abstract looks something like this:

Join SQL Server expert Brent Ozar and SQL Server developer Jeremiah Peschka as they give an overview of the free tools you can’t afford to ignore in tough economic times! In this presentation, you’ll see how to improve your productivity with SQL Server Express Edition.

  • SQL Server Express Edition – the free version of SQL Server
  • SQL Server Management Studio Express – the free way to manage your Express Edition instances

The meeting will take place at 6:30 PM on June 11th, Eastern at Battelle For Kids – 1160 Dublin Rd Suite 500, Columbus, OH 43215

LiveMeeting will be available for this event – click here to attend.

Add it to your calendar!

Audio Information
Computer Audio
To use computer audio, you need speakers and microphone, or a headset.
First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
Troubleshooting
Unable to join the meeting? Follow these steps:

1. Copy this address and paste it into your web browser:
https://www.livemeeting.com/cc/usergroups/join
2. Copy and paste the required information:
Meeting ID: Q754Q2
Entry Code: XQX<6\s\G
Location: https://www.livemeeting.com/cc/usergroups

If you still cannot enter the meeting, contact support

Links for the Week 2009.05.22

Big pile o’ link love this week. Honestly, I didn’t include a ton of GREAT links from Brent Ozar because people would start to think that Brent Ozar pays me to link to his site and say Brent Ozar a lot. He doesn’t, but if you click on the links to Brent Ozar maybe he’ll see where the traffic came from and pay me to provide links to Brent Ozar

SQL Server

SQL Server 2008 Developer Training Kit Available for Download Denis Gobo provides a link and a quick summary of Microsoft’s most recent training offering for developers that will help get people up to speed with SQL Server 2008.

PASS Virtualization Virtual Chapter That’s right, we have a new thing at PASS. Well, the same old thing has a new name. SIGs are now Virtual Chapters. And Brent Ozar is now in charge of the PASS Virtualization Chapter. Check it out!

Download – SQL Server 2008 Developer Training Kit Free training. Free training. Freetraining. freetraining.

Excel Functions for SQL Server Sometimes I’ll find myself using SQL Server and longing for something from Excel that one of my more management-type friends has shown me. Now I can, in theory, have some of that Excel love right in SQL Server.

What’s a ‘DBA’? I’ve known for a long time that, while I love data, I’m not a DBA… not 100%, at least. Sam Bendayan answers the question and talks about what job title options there are for database professionals

Development

MvcFluentHtml – Fluent HTML Interface For MS MVC ASP.NET MVC doesn’t us a bad method to generate HTML, but there are definitely smoother ways, depending on how preference. Fluent HTML uses one paradigm to make it a bit easier to generate HTML in your views. It’s closer to how Ruby on Rails does things, and I like Rails. A lot. Almost as much as I like SQL Server.

Dear Art Director…

Stuff & Things

The Information Architecture of Personal Music Collections Dan Brown, famed Information Architect not famed author, spent a lot of time thinking about how people interact with music libraries. The poster is from 2005 but, shockingly, not a lot has changed since then.

11 Striking Findings From an Eye Tracking Study Eye tracking is some great stuff, it’s right up there with click tracking. It helps us, as bloggers, figure out what you, the readers, are paying attention to.

How to Maintain a Healthy Lifestyle When You’re Too Busy To Care Title says it all. Lazy? Want to get in better shape? Do this.

Evil Lair: On the Architecture of the Enemy in Videogame Worlds I don’t know what to say about this, really. This is a fascinating article about how architecture current works its way into video games and also how it could be used.

10 for $10 hardcore summer tour This is the coolest idea for a summer tour – 10 bands for $10. If you’re at all into hardcore punk, it’ll be a great show. If you aren’t (which is more than likely since you’re reading this blog), take note because it’s an interesting idea that you might see more of in the future.

How to Build Your Own PC WARNING: NOT SAFE FOR WORK SomethingAwful.com is often flagged as adult content. Don’t visit it if you like keeping your job. That being said, this is a hilarious look at building your own computer. It’s based on Brent Ozar‘s experiences building his hackintosh.

CBusPASS Meeting – 2009.05.14

Yup, it’s that time again. Time for you to get your SQL shoes on and head on out to CBusPASS, your Columbus source for SQL Server related information. Apart from MSDN… and the library… and the internet.

When: Thursday, May 14th, 6:30PM – 8:30PM
Where: Battelle For Kids, Suite 500, 1160 Dublin Rd, Columbus, OH 43215

IMPORTANT NOTE: Battelle For Kids has moved to Suite 500, which is on the opposite end of the building from where it used to be.

Food and drinks will be provided.

If you have problems locating the venue, you can hit me up on twitter or via telephone/text at 614.515.0727

Using Cloud-Based BI to Interpret Perfmon & Profiler Results

After learning how to use Perfmon and Profiler to gather performance statistics about your SQL Server, it still takes a lot of time to interpret those results and figure out what’s going on. Microsoft’s SQL Server Data Mining team has built a free cloud-based data mining tool for Excel that can help slice and dice mountains of data and help you make sense of it all.

Even if you’re not ready for BI in the cloud, you can use this same type of tool in combination with a local SQL Server Analysis Services instance. Wait! Don’t freak out – it’s much easier than you think, and you never have to leave the comforting environment of Excel. Even if this doesn’t sound like fun to you, you might want to learn about it because mid-level managers in your company might want to use this technique to analyze sales or customer data.

Attendees will learn how to install & configure data mining in Excel, how to analyze Perfmon data to break the server’s load into categories, and how to use BI to write a performance report about your SQL Server.

Brent Ozar

Brent is a SQL Server Domain Expert with Quest Software. Brent has a decade of broad IT experience, performing systems administration and project management before moving into database administration. In his current role, Brent specializes in performance tuning, disaster recovery and automating SQL Server management. Previously, Brent spent 2 years at Southern Wine & Spirits, a Miami-based wine & spirits distributor.

Brent has experience conducting training sessions, has written several technical articles, and blogs prolifically at http://www.BrentOzar.com. He’s currently writing SQL Server Internals and Troubleshooting for Wiley/Wrox along with Christian Bolton, Justin Langford and Cindy Gross. He’s Editor-in-Chief at SQLServerPedia.com, where he also records video podcasts.

If you can’t attend in person, you can join us using LiveMeeting:

Join the meeting.

Audio Information – Computer Audio
To use computer audio, you need speakers and microphone, or a headset.

First Time Users:
To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.

Troubleshooting
Unable to join the meeting? Follow these steps:

1. Copy this address and paste it into your web browser:

https://www.livemeeting.com/cc/usergroups/join

2. Copy and paste the required information:
Meeting ID: NM86HK
Entry Code: 5\-b6|jkH
Location: https://www.livemeeting.com/cc/usergroups

PASS May Webinars

Do you like free stuff? I like free stuff. We should watch a free webinar sometime.

References to Idiocracy aside, I really like free content. Luckily for us, some very kind people have donated their time to bring their knowledge to the masses via free webinars. Want to see what’s coming up? You can mosey on over to SQLBatman’s website and read all about it, or you can keep scrolling.

This is seriously some high quality content that you are going to be able to view for free. Check with your boss and add these events to your calendar, or ignore your boss and do it anyway. The point is that this is some high quality free training that you can watch from the comfort of your desk!

Introduction to SSIS Custom Component Development

Speaker: Anthony Dangelo
Tuesday, May 12th, 12:00pm ET

You have tried so hard not to write code inside of SSIS, but the day has arrived when you tired of writing the same script task over and over again. Don’t fret creating a Custom Component is not as daunting as you might think. This session will integrate your logic with SSIS Components: variables, pipeline, and events. This session will explore the desgin-time and run-time events, the difference between Syncronous and Asyncronous Components, and debugging techniques.

For dial in information, click here.

To add this meeting to your calendar, click here.

Custom Security with Reporting Services

Speaker: Cherie Sheriff
Thursday, May 14th, at 1:00pm ET

In this session we will discuss different custom security approaches with SSRS and what considerations need to be made when deciding upon a strategy for security as well as the risks and benefits of each approach.

For dial in information, click here.

To add this meeting to your calendar, click here.

Rolling Your Own Replication

Speaker: Brent Ozar
Tuesday, May 19th, 1:00pm ET

SQL Server’s built-in replication has made great strides in the last couple of versions, but what if it’s still not enough? One team needed more flexibility, easier administration and higher scalability, so they built their own solution instead. Brent Ozar will discuss how the system was architected, the pros and cons, and how you can build a similar solution for your own needs. He’ll explain some of the lessons learned in scaling this out to thousands of remote SQL Servers.

For dial in information, click here.

To add this meeting to your calendar, click here.

Multi-dimensional Modeling for Performance Management

Speaker: Cherie Sheriff
Thursday, May 21st, 1:00pm ET

The first in a short series about how you can use multi-dimensional modeling to show how well you are performing, how to create budgets or strategic plans and how to create forecasts. Learn how to leverage SSAS and SSRS to give your company the tools it needs to save time and money. In the Performance Management session, learn how to generate easily understood views of the actuals.

For dial in information, click here.

To add this meeting to your calendar, click here.

Introduction to SSAS Dimensions

Speaker: Jessica M. Moss
May 26th 12:00pm ET

Topic Description: SQL Server MVP Jessica M. Moss will provide an introduction to dimensions in SQL Server Analysis Services. The presentation will discuss the different types of dimensions and how to create dimension attributes, hierarchies, and properties. Finally, we’ll discuss the different properties of dimensions used to create more performant SSAS processing and querying.

For dial in information, click here.

To add this meeting to your calendar, click here.

Rated G for Nerdy Content

My fellow DBAs and SQL Server Developers, have you ever worried about being associated with other, perverted, developers who might use profanity or nudity in their presentations? Are you concerned that people might not know what kind of content to expect in your presentations?

Worry no more!

Even C++ developers can understand this!

Even C++ developers can understand this!

Now you can declare to the world that your presentation is free of filth and only contains worthwhile knowledge and information. No more will people confuse you with some kind of filth monger. No more will people cringe in fear when you mention your up time. Rejoice my fellow developers!

Solving Business Problems with SQL

Businesses have all kind of interesting rules for working with data. Sometimes these rules are incredibly easy to implement in the database. Sometimes these rules are incredibly to implement in the application layer. Sometimes, it’s difficult to construct these rules no matter where you are in the entire application stack.

I recently came across a situation that required a bit of head scratching before I got things working correctly. What made this incredibly interesting to me was the apparent simplicity of the business rules.

The stored procedure must return a set of users, given an administrator’s user id, that the administrator is able to edit. An administrator is able to edit a user if the following criteria are met:

  1. There is at least one client in common between the administrator and the user.
  2. A user’s set of clients must all be members of the admin’s set of clients.
  3. If conditions 1 & 2 are not met, the user is excluded from the set and is effectively invisible to the administrator.

Before getting started working on real data, I created a sample set of data that I can share here:

IF OBJECT_ID('tempdb..#users') IS NOT NULL
  DROP TABLE #users;
GO

CREATE TABLE #users
(
  UserId INT,
  ClientId INT
);
GO

-- Admin
INSERT INTO #users VALUES (1, 1);
INSERT INTO #users VALUES (1, 2);
INSERT INTO #users VALUES (1, 3);

-- User with two clients
INSERT INTO #users VALUES (10, 1);
INSERT INTO #users VALUES (10, 2);

-- Another user with two clients
INSERT INTO #users VALUES (11, 2);
INSERT INTO #users VALUES (11, 3);

-- User with same clients as admin
INSERT INTO #users VALUES (12, 1);
INSERT INTO #users VALUES (12, 2);
INSERT INTO #users VALUES (12, 3);

-- User with overlapping set of clients
INSERT INTO #users VALUES (20, 2);
INSERT INTO #users VALUES (20, 3);
INSERT INTO #users VALUES (20, 4);

-- User with no matching clients
INSERT INTO #users VALUES (21, 4);
INSERT INTO #users VALUES (21, 5);
INSERT INTO #users VALUES (21, 6);

So, let’s start with an initial query:

SELECT *
  FROM #users AS a
       INNER JOIN #users AS b
          ON a.ClientId = b.ClientId

This really doesn’t tell us much, but it does give us a list of all users and any users who share the same client.

By adding a predicate to make sure that the user from the ‘a’ table is our administrator, like so:

SELECT *
  FROM #users AS a
       INNER JOIN #users AS b
          ON a.ClientId = b.ClientId
 WHERE a.UserId = 1

we’ve effectively fulfilled the first requirement:

There is at least one client in common between the administrator and the user.

Unfortunately, that’s the easy part. Determining if the user’s set of clients are a subset of the administrator’s set of clients is a little bit trickier. This is, actually, where a full outer join becomes incredibly helpful.

We’re going to change the query around considerably in order to get the desired results:

;WITH cte AS (
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS row_num,
       a.UserId AS a_UserId,
       a.ClientId AS a_ClientId,
       b.UserId AS b_UserId,
       b.ClientId AS b_ClientId,
       COUNT(*) OVER (PARTITION BY a.UserId, b.UserId) AS admin_count,
       COUNT(*) OVER (PARTITION BY b.UserId) AS user_count
  FROM (SELECT UserId,
               ClientId
          FROM #users
         WHERE UserId = 1) AS a
       FULL OUTER JOIN (SELECT UserId,
                               ClientID
                          FROM #users) AS b ON a.ClientId = b.ClientId
)
SELECT c.*
  FROM cte AS c
 WHERE admin_count = user_count
   AND a_UserId  b_UserId
 ORDER BY b_UserId

So, what did we change? Well, rather than directly joining from #users to #users, we’re using two sub-selects and have changed from an inner join to a full outer join. Changing to a full outer join will, as everyone knows, give us all rows from both queries: even if the user has access to a client but the administrator does not, that user’s information will still be returned.

Second, we’ve changed the core query to only return the administrator, rather than joining on all rows where the Client Ids are the same. Why? Well, we don’t care if other users have access to the same set or subset of clients, we only care if the users and the administrator share a common set of clients.

What’s with all of the COUNT(*) OVER (…) nonsense? Well, by using COUNT(*) and PARTITION BY (as I talked about last week in Using Partitioning Functions to Find Duplicate Rows ) you can detect duplicate rows. What you can also do is determine the count of specific criteria by using the PARTITION BY clause to do some implicit grouping in your query.

The first partition by on both a.UserId and b.UserId provides the row count for the number of times the unique combination of administrator and user occur in the overall result set.

The second partition by function provides the row count of the number rows that contain the user id in the total result set.

If the administrator row count does not equal the user row count we know that there are more user rows than there are administrator rows.

Why did I include the ROW_NUMBER() in the query? When I’m writing these kinds of queries I will typically include the ROW_NUMBER() windowing function so I can apply different criteria in the OVER clause to help keep track of the query. This is especially important when you’re dealing with a query that contains a large number of surrogate keys.

Finally, I wrapped everything in a CTE. This makes it possible to actually apply the count comparisons that I mentioned above. It also makes it easier to perform any additional filtering on the column names that I might need in the future for additional business rules.

Related Reading

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 401 items have been purified.