T-SQL Tuesday #88: Surprise – Those Aren’t Test Accounts!

Welcome back to another edition of T-SQL Tuesday. This month’s host is Kennie Pontoppidan (b|t), who has invited participants to share a WTF story!

A few jobs back, I worked for a software firm. Our system had a complex system of “accounts” which were tied to client companies and users.  And our users could have multiple different accounts through which data would get routed to “make widgets.”  Without going into details, these accounts were simply like an individual’s savings account – they were fairly complex entities which were simply labelled as “accounts.”

My team had been wanting to clean up obsolete account data stored in our account manager database for a terribly long time. Aside from just raw storage, having obsolete accounts lingering in our system had numerous other consequences which made reporting and other things terribly irritating. But our business was always extremely afraid to ever delete anything – so we had account data for everyone we ever had, etc.

As a “pilot,” they agreed to let us finally delete several hundred internal-only accounts. These accounts were obsolete, only used for demo, and were not associated to any client companies, just our company.  As the point person for making this change, I put together a complex T-SQL script to manually remove all of these accounts from the various tables of our database system. But what I also did was put together a backout/restore T-SQL script that restored all of those accounts. I did this out of paranoia and lessons learned from prior experiences. This way one could run my delete script & my restore script repeatedly. The QA team tested my scripts for 1-2 weeks and we were finally given the go-ahead to clean out the stale records.

Monday morning came along and as scheduled, our Production DBAs executed my script before start of business. 30 minutes later, the frantic calls started to reach us. Seems some of our clients could no longer “make widgets!” Accounts that they needed to route data were gone! My manager and I looked at one another in horror – we were only deleting internal accounts!!! We didn’t hesitate and immediately had our Prod DBAs back out the change with my backout script, before the rest of the United Stated started business. The backout was executed immediately and all was back to normal, but business folks were pissed and wanted to know what happened.

As we dug through things, we came to discover that some of our implementations folks had jury-rigged some of their implementations. To meet customer requests for unsupported features, they utilized our company’s internal demo accounts! WTF!!! We in development were furious. Their use of the internal accounts was not documented anywhere, but the data trail didn’t lie.  And these clients weren’t in QA, which is why they never picked it up either!

Moral of the story? Have a robust restore plan. Sure, our systems were fully logged and we could have executed a point-in-time restore. But for a scenario like this, having an immutable data restore script, that was fully tested and ready to be executed, was far faster. It allowed our business to get back online almost instantaneously & saved my bacon.

T-SQL Tuesday #84: Growing New Speakers Round-Up

TSQL2sDay150x150Welcome to this month’s T-SQL Tuesday Round-Up! A few weeks ago, I sent out a call for bloggers and must say that I’m utterly blown away by the response. A whopping FORTY bloggers responded last week with contributions for Growing New Speakers!  Four – zero!  You people are all amazing!!!

I’ve decided to split the list of contributors into three groups.

  • New Speakers: Those who have never presented before!
  • Novice Speakers: Those who have presented just once, just a few times, or perhaps long ago in a galaxy far, far away. Generally if you’ve only spoken a handful of times, been speaking for less than a year, and/or self-identified as a new-ish speaker, you were grouped here.
  • Experienced Speakers: Those who are seasoned speakers.

NEW SPEAKERS

  1. Andrew Pruski-First Foray Into Presenting: @dbafromthecold
    Shares story of first presentation
  2. Angela Tidwell: @angelatidwell
    Writes about things learned at PASS Summit about presenting
  3. Arun Sirpal-SQL Server – Reconfigure: @blobeater1
    Explores RECONFIGURE in a technical blog for a first presentation
  4. Chris Voss: @ceedubvee
    Writes about upcoming first presentations and muses how to progress further
  5. Constantine Kokkinos-Exploring DBA Tools or: How I Learned to Stop Worrying and Love PowerShell: @mobileck
    Blogs about DBATools & Powershell for first presentation
  6. Deb Melkin-If I Were a Speaker…: @dgmelkin
    Explores three ideas for a first presentation
  7. Devon Leann Ramirez: @restinbeachface
    Writes an introduction for first presentation
  8. Jo Douglass: @jodouglass
    Writes about 1st presentation topic idea: surrogate keys as a DW/ETL anti-pattern
  9. Michelle Haarhues-On the Doorsteps: @mhaarhues
    Explores Women In Technology and first presentation about women presenters
  10. Robert Preseau: @robertpreseau
    Writes about overcoming mental obstacles to speaking
  11. Scott Millard-Taking the next step – becoming a speaker: @leftseatsql
    Accepts the challenge to speak
  12. Tywan Terrell: @tyawnterrell
    Writes about T-SQL fundamentals as first presentation topic

NOVICE SPEAKERS

  1. Anthony Nocentino-Public Speaking – The First Time: @nocentino
    Shares an updated recap blog from first presentation
  2. Bjoern Peters-Become a Speaker at a PASS Event or other Meetups – share your knowledge: @sql_aus_hh
    Writes about elements that make for a good presentation
  3. Chris Lumnah: @lumnah
    Reflects on lessons learned after first presentation
  4. Chris Sommer: @cjsommer
    Shares things to think about when writing a new presentation
  5. Kenneth Fisher-Zip to Speaker: @sqlstudent144
    Recaps prior blogs about speaking & offers encouragement
  6. Kevin Hill-Speaking & Presenting: @kevin3nf
    Explores DBA Basics for Non-DBAs as a “first” presentation idea
  7. Matt Gordon: @sqlatspeed
    Shares two key lessons learned
  8. Mike Kane: @tcp1433
    Explores target audience, topic, and format
  9. Monica Rathbun-Helping New Speakers: @sqlespresso
    Writes how to get started
  10. Wylie Blanchard-Use Video as a Tool to Enhance Speaking Skill and Create Content: @wylieblanchard1
    Discusses value & benefits of videotaping one’s self

EXPERIENCED SPEAKERS

  1. Alexander Arvidsson: @arcticdba
    Writes about body language
  2. Andy Yun-Building Your Slidedeck: @sqlbek
    Shares slidedeck building tips
  3. Brent Ozar-The Three Parts of Every Presentation: @brento
    Explores types of presentations
  4. Derek Hammer-Building an Hour of Content: @sqlhammer
    Shares advice in building your first hour long presentation
  5. Doug Lane-Conquer Your Fear of Presenting with a Gift-Giver’s Mentality: @thedouglane
    Presents a video blog about the Gift Giver’s Mentality
  6. Erin Stellato: @erinstellato
    Recaps 4 prior blogs about speaking & addresses topic of comfort
  7. Jes Borland-Dealing with Failure: @grrl_geek
    Discusses how to handle failure on the fly.
  8. John Deardurff-Speaking about SQL: @john_deardurff
    Shares tips about learning itself
  9. Kathi Kellenberger-New Speakers: @auntkathi
    Writes about how to field questions
  10. Lori Edwards-So You Want to Present: @loriedwards
    Builds on prior blog post about speaking, sharing advice learned since
  11. Michael Swart-I’m Trying To Kick My “Undo Button” Habit: @mjswart
    Writes about speaking at PASS Summit for the first time
  12. Mike Fal-Getting Ready for your Presentation: @mike_fal
    Shares how to prepare the day of your presentation.
  13. Mike Lawell-Speak in Public? What? Me?: @sqldiver
    Shares journey about starting speaking.
  14. Riley Major-No One Wants to Eat You: @rileymajor
    Shares his personal story of speaking, followed by a huge list of tips, tricks, and resources
  15. Rob Farley-How I Prepare for a Presentation: @rob_farley
    Writes about deeply exploring your topic
  16. Rob Sewell-Speaking? You? Go on.: @sqldbawithbeard
    Shares advice about getting into speaking
  17. Steff Locke-A note to (potential) new speakers: It’s ok not to be perfect!: @stefflocke
    Reinforces that perfection is not necessary.
  18. Steve Jones: @way0utwest
    Encourages readers to speak.

WHAT COMES NEXT?

As I pledged in the first blog post, I will now be reaching out to all New Speakers, to offer personalized feedback.  A number of Experienced Speakers also volunteered to help, so I will be working out those logistics.  Additionally, if any of the Novice Speakers would like the same kind of help, please contact me – I will add you to the list too!

There are numerous opportunities to present: internally to coworkers, Toastmasters, User Groups, SQL Saturdays, & Virtual Chapters.  And all of them are always looking for new speakers!  When will you speak next?

T-SQL Tuesday #84: Building Your Slidedeck

TSQL2sDay150x150

Welcome to another edition of T-SQL Tuesday. I am this month’s host, and the topic is Growing New Speakers. My contribution to this month’s T-SQL Tuesday was inspired via a tweet by Jonathan Cox (b|t).

the-questionWhen I gave my very first presentation, I had next to no experience with PowerPoint. In fact, I found it a bit intimidating. Where to start? How should I make it look? Do I have to pick a color scheme?

Not to worry! When you first open PowerPoint, there are numerous basic templates already loaded! My advice is to select a template that is simple. Don’t select one that has a background with very cluttered graphics. Visual noise is distracting and is the last thing you want to worry about.

avoid-examples

For your first presentation slidedeck, there’s no need to get fancy. Keep things simple like the templates below.

clean-examples

Readability is very important. What may look fantastic on your 1920×1200 laptop screen that’s 2 feet from you, will look drastically different when it’s been downsized by a projector to 1024×768 and is projected to an entire room.

Font size is the first key factor in Readability. Karen Lopez (b|t) tweeted an excellent tip, that I used when I was working on my PASS Summit slidedeck.

readableI readjusted a handful of my slides to pass this test (thanks Karen!).

Color contrast is important. Different rooms have different lighting conditions, so be sure to use a simple, high-contrast color combination so everyone in your room can read your slides. A lightly colored or white background with dark or black text works best. Stick with the basics – they work.

When it comes to amount of content, don’t write huge walls of text on slides. Put only your main talking points. Your speaking will fill in the corresponding details.  And if you do have a lot of slide content, don’t hesitate to split it into two slides.

Images and clip art. Some like art, I generally shy away from it – it’s all personal preference. If you do use an image from somewhere, you must give credit. Generally a footnote is acceptable. I prefer to rely on Creative Commons 0 images. Makes life hassle free. Check out Kendra Little’s (b|t) blog post all about Easy Free-Use Images.

I hope this collection of tips helps you on your way to building your first slidedeck!  And if you still find yourself a little stumped, Google/Bing is your friend!  There are many out there, who have written numerous articles & blogs on how to build effective slidedecks.  Leverage their collective knowledge.

Happy Powerpointing!

T-SQL Tuesday: #80 Give Yourself a SQL Gift!

TSQL2sDay150x150

This month’s T-SQL Tuesday, is hosting by Chris Yates (b|t). Coincidentally, it is also his birthday today! As such, he’s chosen this month’s topic to be present or gift oriented.

Reading Chris’s announcement post, I thought back to a recent conversation regarding purchasing of tools, to make our lives as data professionals easier. Many of us work for fantastic companies, but may not have the budget or ability to invest in tools for us.

My challenge to everyone is to consider giving yourself a gift and and purchasing a tool for yourself. Think about what you do on a regular basis:

  • Do you often find yourself comparing “identical” databases for drift or other reasons?  Like making sure pesky developers didn’t sneak in yet another index without informing you first?  Wouldn’t RedGate’s SQL Compare make your life more awesome?
  • Do you dig through Execution Plans regularly? How about investing in SQL Sentry’s Plan Explorer Pro version?  Because you’re already using the FREE version & know it’s awesome, right?  RIGHT?!?
  • Sling a lot of T-SQL code daily? How about Mladen Prajdić’s SSMS Tools Pack, which is chock full of awesome features that make a T-SQL dev’s life more awesome.

I will fully admit that the cost of any of these tools is non-trivial.  But on the other hand, this is about giving yourself a gift.  And this gift is hopefully something you’ll use on a regular, if not daily basis, in the course of your career.  Consider the value that such a tool would bring to your life.  So go ahead… treat yourself to a gift!

T-SQL Tuesday #77: My Favorite SQL Server Feature

TSQL2sDay150x150

Hello everybody!

I’ve been away from blogging for a bit longer than I care for, but Jens Vestergaard’s (b|t) T-SQL Tuesday Topic has brought me back into the fray.

What is my favorite SQL Server Feature?

Dynamic Management Views & Functions (DMVs & DMFs)

What are these? It is said that one’s eyes are the gateway to the soul, I say that DMVs/DMFs are the gateway into SQL Server! Formally speaking, the DMVs/DMFs expose internal information about your SQL Server. This information can be used to learn about its current state & health, and provides valuable insight for troubleshooting and tuning purposes.

Much earlier in my SQL Server career, I never knew much about how SQL Server operated under the hood. I only had knowledge of the things I could do directly, but I never questioned what was really happening behind the scenes. Then I attended SQLskills IE1 training, which was a turning point in my career. Among other things, it was my first exposure & deep dive into SQL Server Internals. I became enamored with learning how things really worked under the hood and the DMVs/DMFs became one of my best friends.

Since their introduction in SQL Server 2005, the number of available DMVs/DMFs has more than doubled. How can you see what’s available to you on a given SQL Server? One quick & easy way is to query sys.system_objects:

SELECT
system_objects.name,
system_objects.type_desc
FROM sys.system_objects
WHERE system_objects.schema_id = 4
AND system_objects.type IN (‘IF’, ‘V’)
AND system_objects.name LIKE ‘dm_%’
ORDER BY
system_objects.type_desc,
system_objects.name;


Of these, what are some of my favorites?

  • sys.dm_db_index_physical_stats
  • sys.dm_db_index_usage_stats

Combining these two, gives me very useful insight into both the structure of a table & any indexes it may have, but to how my workload is actively making use of each of these structures. Data found here is extremely useful when it comes to performance tuning.

  • sys.dm_db_partition_stats

I like to use this DMV to get row count & page count information about a database. Its output gives me greater insight into the contents of a table, particularly without the overhead of a SELECT(1) for a quick row count or sp_spaceused execution. Personally I find knowing size by page count to be far more valuable anyway.

  • sys.dm_db_exec_connections
  • sys.dm_db_exec_requests
  • sys.dm_db_exec_sessions

Mixing & matching these three, you can obtain information regarding current connections and activity on your SQL Server.


I can’t tell you how many times I’ve had a “eureka” moment, discovering that a DMV/DMF exposed another interesting piece of information that I wasn’t aware of before. To say that there’s a wealth of information is an understatement. So whether you’re new or not to DMVs/DMFs, take another look – you too may find a new and useful gem hidden inside them!

And if you want to read all about all available DMVs/DMFs, be sure to check out Books Online: Dynamic Management Views and Functions (Transact-SQL)

T-SQL Tuesday #68: Round-Up

A couple of weeks ago, I posted an Invitation to T-SQL Tuesday #68: Just Say No to Defaults. Last week, #SQLFamily responded in force with 22 blog posts! There’s a fantastic wealth of information across all of these blog posts and I was blown away!

Without further ado, here’s the round-up!

I want to thank everyone for participating and sharing your knowledge. And I hope that those of you who are reading, but not yet blogging, will join us, start your own blog, and begin sharing your knowledge and your stories too!

Until next time!

T-SQL Tuesday #68: Changing SSMS Keyboard Query Shortcut Defaults

Welcome everyone!

TSQL2sDay150x150
After being a long time read and occasional participant, I am honored and humbled to be your host for this month’s T-SQL Tuesday! In my Invitation to T-SQL Tuesday, I asked everyone to write a blog having something to do with “Defaults.”

For my contribution, I decided to blog a bit about SQL Server Management Studio. As a SQL Server Developer, I live my life within SSMS. As much as I like it, there are a variety of defaults that I like to change. And for today’s blog, I’m going to talk about Keyboard Query Shortcuts.

If you navigate to Tools -> Options -> Environment -> Keyboard -> Query Shortcuts, you will find that SSMS comes with a handful of defaults.

1_Options
Tools -> Options

2_Query Shortcuts - Default
Query Shortcut Defaults

These three starting shortcuts are indeed very handy, but SSMS gives us a number of other blank entries to add our own. Wouldn’t it be a waste if we did not take advantage of them, to add in some of our own?

2_Query Shortcuts
My Default Changes

As you can see above, here are ALL of the new Keyboard Query Shortcuts that I add. And here they are in full:

  • Ctrl+3 = sp_help
  • Ctrl+4 = sp_helptext
  • Ctrl+5 = sp_SQLskills_SQL2008_helpindex
  • Ctrl+6 = sp_SQLskills_SQL2012_helpindex
  • Ctrl+7 = EXEC sp_whoisactive @get_plans = 2, @get_transaction_info = 1, @get_task_info = 2, @get_avg_time = 1, @get_outer_command= 1
  • Ctrl+8 = EXEC tempdb.dbo.sp_help
  • Ctrl+9 = EXEC sp_helpExpandView @ShowObjectCount = 1, @ViewName =
  • Ctrl+10 = EXEC sp_whoisactive @get_plans = 2, @get_transaction_info = 1, @get_task_info = 2, @get_avg_time = 1, @get_outer_command= 1, @delta_interval = 10

Let’s explore how I make use of each of these!

sp_help & sp_helptext

I use these two SQL Server built-in stored procedures on an almost daily basis. They’re extremely useful while in the midst of code, to check aspects of objects. How do you make use of it? Simple! All you have to do is highlight the object in question, then hit your Keyboard Shortcut!

3_sp_help

Using sp_help, I can quickly peruse all available columns in a given object, double-check their datatypes, or take a quick glance at what foreign keys and constraints are in place.

4_sp_helptext

With sp_helptext, I can quickly scan the contents of a view or stored procedure, when I don’t want the hassle of finding it & script it out via the Object Explorer.

sp_SQLSkills_SQL20xx_helpindex

SQL Server comes with a built-in stored procedure: sp_helpindex. sp_help also returns index information about a table. However, they don’t return everything. When I’m query tuning and checking underlying indexes, I need to know about INCLUDE columns. That’s where Kimberly Tripp’s sp_helpindex rewrite comes in.

5_sp_sqlskills_helpindex

Used in the same fashion as sp_help & sp_helptext, I now have in-depth index information available at my fingertips!

sp_whoisactive

“Hey, why’s the server running slow right now?” Every time I hear that question, Adam Machanic’s sp_whoisactive is the very first thing I always run. If you don’t use this tool already, read more about it on Adam’s blog and install it NOW!

While you can run it without parameters, I like having some additional data points available to me, which require parameters. As you can see from the above command list, that’s a heck of a lot to memorize and re-type, so I’ve mapped that to Control-7.

tempdb.dbo.sp_help

If you’re like me and work with a temporary tables regularly, you’ll notice that the usual sp_help shortcut does not work. Not having sp_help information conveniently available for temporary tables is rather obnoxious, hence this particular Query Shortcut.

6_sp_help_temptbl-1
Executing sp_help against a temporary table, in a user database context, returns an error.

6_sp_help_temptbl-2
But with a modfication to execute from tempdb, we can get our sp_help data again!

Now I can have the same sp_help functionality and convenience with my temporary tables!

sp_helpExpandView

My final Query Shortcut executes my custom tool sp_helpExpandView. Used in the same way as sp_help, I can quickly reference underlying objects of a view. If you have to deal with untangling nested views, I would encourage you to check it out!

That’s it for my SQL Server Management Studio Keyboard Shortcuts. I hope you all found this insightful. If there are any Defaults that you like to change in SSMS, please feel free to share in the comments. Thanks for reading – until next time!