SQLvariations: SQL Server, a little PowerShell, maybe some Hyper-V Rotating Header Image

Productivity

FWIW: #EXCHHelp or #EXCHGHelp?

I saw a tweet on the #SQLHelp hotline last night from Mike Talon ( blog | twitter ) asking “Is there an #Exchange version of #SQLHelp?”

image

My immediate reaction was: Wow!!  What a compliment to the #SQLPASS community that other communities want to help each other like we do!  [Insert Giant Community Pat-On-The-Back]

I know less than nothing about Exchange.  I’m pretty sure that it runs on Windows and I of course know that you can manage with PowerShell ;-) Oh, and my Outlook doesn’t work if it can’t connect to Exchange; and that’s pretty much it.  So in the spirit of #SQLHelp I had to lend what hand I could, and that’s only in naming.  The key is to be short and recognizable.

  • #EXCHelp  Can’t do it because people could mistake the hash for Excel.
  • #EXCHHelp  Was my suggestion because it’s short and hopefully recognizable to them.
  • #EXCHGHelp  Was Mike’s idea, he said that EXCHG was a common way of referencing Exchange. 

I really have no idea what’s going to be a success for them here but I wish them the best of luck in getting the word out on whichever hashtag they settle on.

image

PowerShell Learning Resources

Yesterday a conversation on twitter about PowerShell learning resources lead me to realize that: The PowerShell tab on my own site could use some updating BUT: It’s grown to the point where it’s probably not all that useful for someone starting out. To that end here are 7 8 key resources that I would recommend for learning PowerShell:

  • PowerScriptingListen to the PowerScripting Podcast
  • The Show Notes for the PowerScripting Podcast are freaking treasure trove of info so subscribe to that blog and go exploring what was mentioned in past shows.
  • GetScriptingSubscribe to Jonathan Medd’s PowerShell 2.0: One Cmdlet at a Time blog series.
  • Jonathan Medd also co-hosts a podcast on PowerShell. Subscribe to both of these, load them on the mp3 player and listen to them on your way to work. You’ll learn without realizing it.
  • imageWindows PowerShell In Action (Second Edition): An excellent book that even includes some of the “hows” and “whys” they made the tough decisions in this new language.
  • Get yourself on the PowerShell Tip of the Day email (or RSS Feed)
  • imageWindows PowerShell™ 2.0 Best Practices: This book is really thick but it is written in a way that is very easy to read even for people that are sill learning. Everyone should feel comfortable picking up this book.
  • ScriptingGuys Of course: If you run into a problem just tweet the ScriptingGuys. Also be sure to subscribe to their daily blog (including weekends & holidays) where they lay out how to solve all kinds of questions people ask of them. And if you problem is longer than a tweet. Scripter@Microsoft.com
  • geekSpeak and of course I can’t finish without saying: If you need some help getting started from scratch using PowerShell with SQL Server check out my video on MSDN’s geekSpeak and blog series from SQL University.

I use quite a few more learning resources but this is where I started and where I would recommend for people to get started. I hope this helps! :-)

Controlled Failure is the Key to Learning More

TSQL2sDay150x150Recently Andy Leonard ( blog | twitter ) tweeted: “I was asked recently about secrets to success. My reply? “Never fear failure.” :{>” I really agree with this in a lot of ways. Surprised? Don’t be, there’s a big difference between ‘not fearing failure’ and ‘liking failure’. I don’t get up in the morning because I like to fail, I just know that it’s going to happen. A lot.

I approach a new programming feature by reading through it’s capabilities one command at a time. After I’ve read the definition of a command then I like to play with the examples. After that I’ve done some of the things it says it can do, then I like to try and make it do things that weren’t actually listed. I like to test the boundaries of a feature. This is where some “controlled failure” comes in.

Boundary testing is useful for a number of reasons. A best practice for using the feature might be established, but without testing the boundary you won’t understand why it is the best practice. When I’m done testing boundaries for myself I look at what others have done with the feature. I find out what problems they’ve experienced and what innovations they discovered. Because I’ve tested the boundaries myself I can better understand examples online and discuss these discoveries with other data nerds. By doing this I learn from my failures and other peoples failures too.

This appetite for failure spills over into my work–and I’d bet it spills over into your work too. At the end of the day though no matter how big or awesome a solution we create chances are a ton of failure that went into it. On a good day I probably fail at trying more things by noon than most people do all day, heck maybe even all week. Embrace failure as part of the learning process. It makes you a better employee and even a better mentor at work, because let’s face it, if you can fail and then persistently succeed yourself then you’re better positioned to help a struggling coworker find that persistent success too.

Bite Sized Blog Posts

For the next several weeks (about 9) I will be really busy with a data center move and doing some presentations on PowerShell.  During that time I’m sure I’ll find all kinds of cool uses for PowerShell and SQL Server and I’ll post them as quick as I can in a small bite-sized format.  This will make it quick and easy for people to read and for me it will mean much less time to get a post ready.  Sometimes when getting a blog post ready I will take as many a 8 screen shots of the same thing just trying to make sure that I got everything easy to understand, syntactically correct, and useful.

 PoSh image

Once I’m done with all this (around May) I will come back and thread these posts together into a bigger story and show you how much time we saved from end to end.  So far I already have about 3 of the bite-sized posts that I need to write and we’ve saved at least 4 hours on tasks that previously would have required loads of manually clicking around.

I hope this format helps people easily take advantage of what I’ve found useful between leveraging SQL and PowerShell.

btw…  If you’re looking to learn more about PowerShell during your daily commute I HIGHLY recommend that you subscribe to the PowerScripting Podcast.  My coworker Shyam and I are catching up on back episodes and listening to it nearly every day on the way into work.  They don’t talk about SQL Server too much but what they do talk about is still very useful to us.

Lunch-n-Learn #01: SQL Server 2005 Features

Yesterday I did a quick Lunch-n-Learn here at my company on a few SQL Server 2005 features and this post is just a follow-up to remind everyone what we saw and where you can find those features.  I will try to still make this useful for those of you who didn’t attend.

0:  To make any of these code examples work please download and install the Sample Databases for SQL Server.  (Don’t worry, they’re pretty small.)

  1. The first thing that you folks saw was the intelli-sense where as I was typing the name of a table and SQL Server Management Studio (SSMS) was finishing the table name for me.  That was the only SQL Server 2008 exclusive feature that you saw in the entire session.  You can only see this if you have the SSMS 2008 client pointed to a SQL 2008 db.
  2. I showed you guys how to find out the name of every table and column of the db that you are in using the system views:
    SELECT *
    FROM INFORMATION_SCHEMA.TABLES
  3. SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS

  4. Ticks!  How did this apostrophe get into our db?  And how do we get it out?
    SELECT  [Comments] ,[ProductReviewID] ,[ProductID] ,[ReviewerName] ,[ReviewDate] ,[EmailAddress] ,[Rating] ,[ModifiedDate]
      FROM [AdventureWorks].[Production].[ProductReview]
  5. Well you just use 2 ticks to insert a single tick.  Said again, you use “’’” to insert “” into SQL. Here’s an example from the AdventureWorks database:
    SET IDENTITY_INSERT [Production].[ProductReview] ON
    INSERT [Production].[ProductReview] ([ProductReviewID], [ProductID], [ReviewerName], [ReviewDate], [EmailAddress], [Rating], [Comments], [ModifiedDate])
    VALUES
    (6, 709, ‘John Smith’, CAST(0×0000941800000000 AS DateTime), “>‘john@fourthcoffee.com’, 5
    , ‘I can”t believe I”m singing the praises of a pair of socks, but I just came back from a grueling
    3-day ride and these socks really helped make the trip a blast. They”re lightweight yet really cushioned my feet all day.
    The reinforced toe is nearly bullet-proof and I didn”t experience any problems with rubbing or blisters like I have with
    other brands. I know it sounds silly, but it”s always the little stuff (like comfortable feet) that makes or breaks a long trip.
    I won”t go on another trip without them!’
    , CAST(0×0000941800000000 AS DateTime))
    SET IDENTITY_INSERT [Production].[ProductReview] OFF

    And we can get it out like this:
    UPDATE [Production].[ProductReview]
       SET Comments = REPLACE(Comments, ””, )
     WHERE ProductReviewID = 6

  6. To make your keyboard as useful as mine what you do is open up SSMS click on Tool > Options > Environment > Keyboard >and add the commands that you would like the corresponding shortcut key to execute.
    image
  7. What Exactly is XACT_ABORT?  When XACT_ABORT is ON SQL Server will stop and roll back the transaction as soon as it hits an error; it won’t continue processing all the way to the end.  “When SET XACT_ABORT is OFF, in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing.”
    Use this script to see it work for yourself.
  8. The next feature that I showed you was how you can create an Identity Column for the data you are  selecting without having to insert the data into a table by using the ROW_NUMBER() function.  I mentioned several other features along with that one and I will demo those features in our next Lunch-n-Learn.  In the meantime here’s a script that will show you it do 4 different row numbers on 4 different fields all at the same time.
    /* SQL Purists: please don’t freak out at this script, I’m just showing functionality*/
    SELECT TOP 500 *
                 ROW_NUMBER
    () OVER (ORDER BY AvgCPUTime DESC) AS 'AVG Time Rank'
          
    ,     ROW_NUMBER() OVER (ORDER BY total_cpu_time DESC) AS 'Total CPU Rank'
          
    ,     ROW_NUMBER() OVER (ORDER BY total_duration_time DESC) AS 'Total Duration Rank'
          
    ,     ROW_NUMBER() OVER (ORDER BY total_execution_count DESC) AS 'Total Executions Rank'
          
    , a.TEXT AS 'StatementText'
          
    , a.total_cpu_time
          
    , a.total_execution_count
          
    , a.total_duration_time
          
    , a.AvgCPUTime
          
    , a.number_of_statements
          
    , a.plan_handle
          
    , SUBSTRING(a.TEXT, 1, 100) AS 'hundy', a.name
      
    FROM (
          
    SELECT
                
    sql_text.TEXT,
              
    SUM(qs.total_worker_time) AS total_cpu_time,�
              
    SUM(qs.total_elapsed_time) AS total_duration_time,�
              
    SUM(qs.execution_count) AS total_execution_count,
              
    SUM(qs.total_worker_time) / SUM(qs.execution_count) AS AvgCPUTime,
              
    COUNT(*) AS  number_of_statements,�
              
    qs.plan_handle , db.name
          
    FROM�
              
    sys.dm_exec_query_stats qs
              
    CROSS apply sys.dm_exec_sql_text(sql_handle) AS sql_text
          
    LEFT OUTER JOIN sys.databases db
            
    ON sql_text.dbid = db.database_id
          
    --WHERE dbid = 10
          
    GROUP BY sql_text.TEXT,
          
    qs.plan_handle , db.name
    )a
    ORDER BY AvgCPUTime DESC
  9. Comparing which way is better.  To compare how long and how much data was needed to satisfy two different queries you can just click on the Include Client Statistics button before you run the first query and it will start capturing the statistics for you:
    image
  10. And finally the built-in reports.  To run any of them just Right-Click any database in SSMS Object Explorer and navigate to the report that you want:

That pretty much wraps it up for what we covered yesterday.  I will put some examples together for the Common Table Expressions (CTE), RANK, DENSE_RANK, and NTILE fuctions that I mentioned yesterday so that we can go over them at the next one.  Next Tuesday work good for you?  :-)
If you would like anything else covered you can just email me or comment here.

Goals for 2010

It’s that time of year so here’s a quick blog post so that I can track how well I achieve my goals for 2010

My goals for 2010 are pretty simple.

  • Spend more time with my daughter
  • Finish reading my PowerShell In Action book
  • Help run and market a very successful year of the App Dev Virtual Chapter for PASS
  • Not Die
    • (It’s George Carlin’s secret to life after all)
  • Get certified in Hyper-V: Windows Server 2008 R2, Server Virtualization
  • Do at least 4 different speaking engagements on at least 5 different topics
    • (meaning: User Group, Lunch-N-Learn, SQL Saturday, SQL Lunch, Code Camp??)
  • Use PowerPivot at least once before May
  • Read a second PowerShell book from cover-to-cover
  • Get at least one report to do something/anything with Map Point 2009
  • Show the value of community so that I can get my company to pay to send me to the PASS Summit once again.
  • Write a scathing review on every book that I read
    • Just checking to see if you’re really paying attention
  • Get every db in my current company upgraded to SQL Server 2008 SP2
  • Get my backyard back under control
  • Convince PASS to move the 2011 Summit to somewhere within the Eastern or Central Time Zones.
  • And of course: drop 20 pounds.

And why am I bothering to post this you might ask?  Well I hear the way to make God laugh is to tell him your plan.  :-)

Second Time Zone in Outlook Calendar

I wanted to take a minute today to try and give everyone that is going to the PASS Summit a helping hand with being in a different Time Zone next week.  As nice as it would be if we could all focus in on just the PASS Summit, some of us might still have some commitments back home and maybe even some people back at the home office that for some strange reason think that setting up a conference call might be necessary.  This should help you and you might even want to show it to a few people around the office (then again you might not.)

Here are the steps:

Step #0:  Open Outlook

Step #1:  Go to Calendar and hover over open space and right-click

Step #2:  After Right-Clicking select “Change Time Zone”

Step #3:  When you get the Pop-Up

 Step #4:  Now See the results

 And that’s all there is to it :-)