Tuesday, September 13, 2011

T-SQL Tuesday 22 Data Presentation

Hello Dear Reader, today is T-SQL Tuesday #22.  I’ve been out of the T-SQL Tuesday game for a little while and wanted to jump back in.  This edition is being brought to us by Robert Pearl (@PearlKnows| Blog ), so Robert what is the topic this month?
Therefore, the topic of this month’s T-SQL Tuesday is, “data-presentation” Or put better, formatting data for presentation to the end-user.
We may be the developers, and techno-geeks behind the code, whether simple, advanced, spaghetti, or otherwise.  But, the data the user sees is most critical.  The query output, the report, or data presentation, must be absolutely formatted in such a way that is easily understandable and readable by the end-user.  The end-user can be the boss, supervisor, department head, the analyst, employees, or customers.  And they must be the ones we cater our queries to!
Therefore, I am inviting you all to write about “data presentation” to the user.   This can be in the form of T-SQL code, an SSRS report, etc.  What can you do to streamline data presentation?  I used a CTE, you can use one, but you don’t have to.  No hard format, just be creative, and mention the importance of data presentation.

Data Presentation It IS!

IT’S ALL IN THE PRESENATION



I must confess I’m a bit of a snob when it comes to code.  I will stop, reformat, and then read code if it is not formatted correctly.  But I also believe that what you do every day becomes habit.   And good coding standards are a habit that you want to get into.  This isn’t cool, this isn’t sexy, it isn’t functional (your code will work poorly formatted), and it may take a little longer to type out.

“So Balls,” you say, “Why should I do this? If it will not benefit me?”

AH Dear Reader because easier isn’t necessarily the best way to go.  This is one place where it is better to put in the extra work.  Let’s just look at a very simple example.  Let’s use some DMV’s to get an execution plan. *You would NOT want to execute this statement on a busy server.  This would pull all active requests and their XML execution plans. *

SELECT * FROM sys.dm_exec_requests der CROSS APPLY sys.dm_exec_query_plan(der.plan_handle)

All of this can fit on one line.  But should it?  When we look at this we are doing a select star, pulling back everything on the server.   When your doing a select *, in most cases, you are trying to figure out what rows you are trying to select.   When you ship to production you should be trimming the columns that you do not need.  We’ll get to that eventually but for now let’s do some formatting.

This is the way I write my code, no one way is right for everyone, so please take this with a grain of salt.  First things first, let’s add some space.

SELECT
     *
FROM
     sys.dm_exec_requests der
CROSS APPLY
     sys.dm_exec_query_plan(der.plan_handle)

I like my key words on separate lines, and I like indentation of values that I want to return and table names.  Now when you read this, it is a lot easier to understand what it is that we are looking at.  So let’s go a little farther and trim down the number of columns we are looking at.  All we need is an execution plan.
SELECT
     der.session_id
     ,deq.query_plan
FROM
     sys.dm_exec_requests der
CROSS APPLY
     sys.dm_exec_query_plan(der.plan_handle) deq

This is starting to shape up.  If you execute the other query you will see that we are pulling back a lot of columns that we do not need.  That is data coming over the wire. 

So these have been simple, but let’s look at another coding example that uses a CTE.  I use this in my demo’s for Compression.  This takes a look at the index operational stats dmv and helps you determine the update and scan activity that are occurring on your tables.  This is sizeable and complex, and if you didn’t have formatting it would be nigh unreadable.


WITH IndexUsage(tableName, IndexName, [Partition], IndexID, IndexType, USAGE, Percentage)
AS(
SELECT
     (ss.name + '.' + so.name)
     ,si.name
     ,ios.partition_number
     ,ios.index_id
     ,si.type_desc AS indexType
     ,'UPDATES'
     ,(ios.range_scan_count *100.0/
     (ios.range_scan_count +
     ios.leaf_delete_count +
     ios.leaf_insert_count +
     ios.leaf_page_merge_count +
     ios.leaf_update_count +
     ios.singleton_lookup_count)) AS percentScan
FROM
     sys.dm_db_index_operational_stats(DB_ID(),NULL,NULL,NULL) ios
     JOIN sys.objects so
     ON so.object_id=ios.object_id
     JOIN sys.indexes si
     ON si.object_id = ios.object_id AND si.index_id = ios.index_id
     JOIN sys.schemas ss
     ON so.schema_id = ss.schema_id
WHERE
     (
          ios.range_scan_count +
          ios.leaf_insert_count +
          ios.leaf_delete_count +
          ios.leaf_update_count +
          ios.leaf_page_merge_count +
          ios.singleton_lookup_count)!=0
     AND OBJECTPROPERTY(ios.object_id, 'IsUserTable')=1  
UNION ALL

SELECT
     (ss.name + '.'+ so.name)
     ,si.NAME
     ,ios.partition_number
     ,ios.index_id
     ,si.type_desc
     ,'SCANS'
     ,(ios.leaf_update_count *100/
     (ios.range_scan_count +
     ios.leaf_insert_count +
     ios.leaf_delete_count +
     ios.leaf_update_count +
     ios.leaf_page_merge_count +
     ios.singleton_lookup_count))
FROM
     sys.dm_db_index_operational_stats(DB_ID(), NULL, NULL, NULL) ios
     JOIN sys.objects so
     ON so.object_id = ios.object_id
     JOIN sys.indexes si
     ON ios.object_id=si.OBJECT_ID AND ios.index_id=si.index_id
     JOIN sys.schemas ss
     ON so.schema_id=ss.SCHEMA_ID
WHERE
     (
          ios.range_scan_count +
          ios.leaf_insert_count +
          ios.leaf_delete_count +
          ios.leaf_update_count +
          ios.leaf_page_merge_count +
          ios.singleton_lookup_count) !=0
     AND OBJECTPROPERTY(ios.object_id, 'IsUserTable') =1
)
SELECT
     iu.tableName
     ,iu.IndexID
     ,iu.IndexType
     ,iu.USAGE
     ,iu.Percentage
FROM
     IndexUsage iu
ORDER BY
     iu.tableName
     ,iu.IndexName
     ,iu.Percentage DESC

WOW, it is a lot of fun to play with, but without formatting this would be a nightmare to read through.  We’ve all had code that we had to read that gave us trouble.  Think of the next DBA that has to come along and read it, and make things a little easier on them.

Hopefully the DBA before you did the same thing!

Thanks,

Brad


Wednesday, September 7, 2011

24 Hours Of PASS!

Hello Dear Reader the 24 Hours of PASS are HERE!  If you have never attended a 24 Hours of PASS this is a great one to hop on board with.  This is the fall preview of all the great content and presenters that will be appearing at the PASS Summit in Seattle coming up in October.  Right out of the gate you have not one but TWO of the greatest presenters that I've ever watched.  So before you read any further Click Here to sign up, and Click Here to read more about the total outstanding line up.

Starting this very morning at 8 AM Brian Knight (@BrianKnight | Blog ) President and Founder of Pragmatic Works!  What is Brian presenting on?


Introduction to Data Mining in SQL Server Analysis Services


Presenter: Brian Knight

Session Details:
Data mining is one of the key hidden gems inside of Analysis Services but has traditionally had a steep learning curve. In this session, you’ll learn how to create a data mining model to predict who is the best customer for you and learn how to use other algorithms to spend your marketing model wisely. You’ll also see how to use Time Series analysis for budget and forecast prediction. Finally, you’ll learn how to integrate data mining into your application through SSIS or custom coding.
 
About the Speaker:
Brian Knight, SQL Server MVP, MCITP, MCSE, MCDBA, is the owner and founder of Pragmatic Works. He is also the co-founder of SQLServerCentral.com, BIDN.com and SQLShare.com. He runs the local SQL Server users group in Jacksonville (JSSUG). Brian is a contributing columnist at several technical magazines and does regular webcasts at SQLShare.com. He is the author of a dozen SQL Server books. Brian has spoken at conferences like PASS, SQL Connections and TechEd and many Code Camps. His blog can be found at http://www.bidn.com.



Amazing!  But it doesn't stop there, Up next is the Founder of the Brent Ozar PLF Brent Ozar(@BrentO | Blog) himself!  What is Brent presenting on you might ask?


SAN Basics for DBAs


Presenter: Brent Ozar


Session Details:
They keep telling you it's a SQL problem - but how can you prove where the real problem is? Learn the basics about your storage options like RAID 5, RAID 10, solid state drives, and why your biggest bottleneck might be a $5 cable. No storage experience required. This session is for production database administrators who've never looked inside the black box of storage before.

About the Speaker:
Brent Ozar is a Microsoft Certified Master of SQL Server 2008, a Microsoft SQL Server MVP, and co-founder of Brent Ozar PLF. Brent has over a decade of experience with SQL Server, systems administration, SAN administration, virtualization administration, and project management. Brent spent 2 years at Quest Software as a SQL Server expert and 2 years at Southern Wine & Spirits, a Miami-based wine & spirits distributor. Brent blogs at http://www.BrentOzar.com like it's going out of style.


And from there it keeps going for 12 solid hours.  But the fun doesn't end there this is 24 hours of PASS not 1/2 a day of PASS.   Tomorrow is another 12 hours from 8 am to 8 am.


What will the 24 Hours of PASS cost you?  A Whole lot of your Hard Earned Nothing!  It requires your time, You can even attend while at work!  All you need to do is register, you will get an email with a Live Meeting link inside.  Take the link and click on it when it is time for the Session!

This is a wonderful opportunity for Free Training!  This is a wonderful opportunity to see the value you will get from the PASS Summit!  And this is a wonderful event to see the content you can get live by attending SQL Saturday's!

SQL Saturday's you say!?  Yes I would bet you that every speaker you see today has appeared at, at least, one SQL Saturday event this year.  So if you love this go look for the SQL Saturday coming to your area and sign up.  I hope to see you there!

Thanks,

Brad

Monday, September 5, 2011

Who Do You Work With, Who Drives You, Who Inspires You?



http://www.flickr.com/photos/95952343@N00/403079866/in/photostream/

It is Labor Day here in the U.S.A. where we celebrate the folks that go to work every day by taking a day off.  Trust me the irony of the holiday is not lost on me. 

I was sitting around Casa De La Balls trying to think of a holiday themed blog.  Most holiday’s we are very busy.  There are Kiddos to attend to, meals to cook, and hopefully some football to watch.  So I have yet to do a “Holiday Themed Blog”.  And to be honest this one was a tricky one at first.

“So Balls,” you say “you’ll ramble on like this for a couple of pages and call it a day?”

I hear you Dear Reader, and I’ll get to the point.  Today is all about work, and there is a saying around the place that I currently work that comes to mind.  “The People Make the Difference.”  And there is a lot of truth to it.  For those of you who are not aware I’m currently a Sr. SQL DBA for Publix Supermarkets.  I studied this company before I decided to leave Washington to join them.  And I really liked what I found, I’m not going to blog about them as a company, but we are a very good one and if you’ve never heard of them I’d encourage you to read up on us.

But today it’s all about the people!


WHO DO YOU WORK WITH?

http://www.flickr.com/photos/ro_buk/311934912/


When you go to work every day you can probably close your eyes and tell me the routine.  I park here, I walk through these doors, I put my stuff down, I check email, I go get coffee, blah blah blah.  But when you think of work there should be some people that you think of right away.  

For the past several jobs that I’ve had I can very easily think of the people that when I saw them my day got better.  They were people who would be fun to hang around, were very intelligent at what they did, or had a great personality that made it a pleasure to work with them.

When you get a good team chemistry going you cannot beat it, and you cannot do that alone.  I started out my job history in the IT field as a programmer.  I learned a lot of great things as a programmer.  How to dissect code and look for patterns, how to figure out what is being done, how to look for resources to become familiar with code you’d never written, and how to make the seemingly impossible possible.  That kind of team chemistry requires trust and confidence. 

Trust that the people around you know what they are doing.  That trust frees you to be as good as you can be in your chosen field.  If you’re always worried about Database Performance then you are going to study it, and it is a field that takes a lot of study. 

You also need Confidence.  You should be confident that your teammates can handle their jobs.  You shouldn’t have to worry about your teammates, I learned about SAN’s from a SAN Engineer that was very smart and was eager to share.  I knew I was learning from him because I was confident in his abilities.  I probably babbled on about database just as much as he did about SAN’s.  That freed me up to become the best Programmer/DBA I could be.



WHO DO YOU WORK WITH THAT TEACHES YOU.

http://www.flickr.com/photos/osowska_marta/5873972885/

But I didn’t get there overnight.  I had a lot of help.  I had some really good teachers, colleagues, and friends.  I remember one very smart friend in particular, who was my boss at the time, that whenever I hit upon a problem and I didn’t know the answer I would ask him, and he would never give me a straight answer.  It was incredibly frustrating.  I remember complaining about it a time or two twenty until one day I realized what he was doing.  When I would ask a question instead of giving me the answer right away he was leading me to the next logical step.

 After a while of this I realized that he was teaching me to troubleshoot the way he did.   My questions then changed from “What does it mean when I see X” to “Where would you go to find more information on X”, and eventually the questions stopped.  I had learned what he knew.  However, like any good mentor he always had some tricks up his sleeve that would impress me from time to time. 

As a manager he taught me to be self sufficient.  When I would mentor new people I would provide them with the information that I knew they needed, but then I would help them to ask the questions so they could learn for themselves.


WHO DO YOU WORK WITH WHO DRIVES YOU?


I had another friend who sat right next to me for a couple of years.  My good pal Smitty.  When I first looked at getting certifications I was looking and getting the full suite of .NET programmer certifications.  Smitty kept saying to me, “Balls we should become DBA’s”.  He kept pushing me to go for DBA certifications instead of programming certifications.  I owe a lot to his persistence.

http://www.flickr.com/photos/rogerssg/4991321088/in/photostream/
At first we both got the 70-431 book together, and my goal was to do a chapter a day.  As I got into the book I realized a lot of what was in there I already did every day.  I was what you would call an, “unintentional DBA”.  It just so happened those things that made up DBA work were my favorite things to do.  While studying for the certifications I found a lot of best practices and would go to our Sr. DBA’s and say “are we doing this”.  When they said no, I would say can I do it.  We were a small shop and the DBA’s were tasked to capacity.  I already had the permissions needed and they said sure.

At a job after the previous one, at a business meeting I met our Vice President of Microsoft Operations.  We had a really nice conversation and we discussed the areas of Microsoft technologies that I was most interested in.  Not surprisingly we discussed SQL Server quite a bit.  A couple months later out of the blue I got an email from the VP forwarding an invitation to the first 24 Hours of PASS.   I signed up and loved every minute of it. 

Fast forward a couple of years and a new place of work and I had some friends, one of whom is none other than Dan Taylor (@DBABulldog | Blog),  that were constantly talking about this SQL Saturday thing.  Last year in Orlando was my first.  And the Impact that my First SQL Saturday had is reflected all over this blog.

When you look at where you are, you’ve got to look at where you’ve been.  Chances are you’ve worked with some people that helped you get there.  Even if it was just a chance email, a someone to study with, or a friend that recommended a new way to learn.  And maybe, just maybe you’ve made someone’s life better just by being you.  We’ve got a saying over at Publix that Mr. George used to say, Publix will be a little better place, or not quite as good, because of you.” 


WHO SUPPORTS YOU WHILE YOU’RE AT WORK



I had a lot of little things that helped move me to where I am today.  But there was one person who is a constant influence and that is my wife.  How do you say Thank You to someone who constantly supports and encourages you? 

When I wanted to pack up the family move to a place in Virginia hundreds of miles from friends and family for a job, she let me do it.   When I wanted to move even further so I could work for the President, and she would have to give up working because my commute would be so long that I would be gone before the kids woke up and home just around dinner, she did it.   Participating in SQL Saturday’s, SQL Rally, the PASS Summit, SQL Server User Groups, when I do those things she’s pulling double duty with the kids, or taking off work, or re-arranging her schedule.  Raising a family is hard work, and I couldn’t do what I’ve done without her help and most definitely all of her hard work.

So today when we celebrate those who work in the good old U.S.A. take a look around you and think of the people that have touched your life in some way.  Say Happy Labor Day, and know that you appreciate their hard work.  Don’t forget about the hard work that those close to home put in as well, because they are the ones that make everything else possible.

Happy Labor Day Everybody (especially you my Wife)!

Thanks,

Brad