Author: DB Dave

  • Customising SQL Management Studio 2012

    I’m setting up my new work laptop, and decided to have a look around the net for what the cool kids were doing these days as far as customising SQL Management Studio 2012.  Surprisingly not a lot seems to have changed (i.e. changing font, adding keyboard shortcuts, and using a trendy dark theme are still the most common tweaks).

    Aesthetics

    So I found a dark theme that I actually might give a chance (I’ve tried a few, but always seem to revert to the default after a few hours).  I’m still not sold on the dark development environment – but there are certainly enough colour combinations available from sites like http://studiostyl.es/.

    SQL Server Management Studio 2012

    Productivity

    I also added my usual battery of keyboard shortcuts; sp_helptext, sp_whoisactive, and a wrapper script that I unimaginatively call sp_helpindex2 (which auto-detects the version of SQL running, and then calls the corresponding version of Kimberly Tripps improved sp_helpindex proc).

    Some other minor tweaks include scripting options (Tools -> Options -> SQL Server Object Explorer -> Scripting), for example adding descriptive headers, checking for object existence, etc.

    There are loads of other tweaks you can make – do yourself a favour and take the time to read through every page of options… I’m sure you’ll find more ways of improving your environment.

    Templates

    I then needed to get my templates setup (which, as I detailed in my previous post, I use to store frequently used scripts and code snippets).  This takes a little jiggery-pokery since SSMS doesn’t natively let you specify a new location for these files.

    What you need to know before starting is how Management Studio handles these template directories; in the following default path, C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\SqlWorkbenchProjectItems, there will be a directory called “SQL” which contains all the default templates.

    SSMS Template Directories

    When you open the templates pane in SSMS it compares the contents of this directory to your user template directory (e.g. C:\Users\username\AppData\Roaming\Microsoft\SQL Server Management Studio\11.0\Templates, or explorer window #2 in the screenshot above), and “syncs” up any differences.  I’m sure this is over-simplifying it, but it’s a good-enough explanation for the purposes of this post. Window #3 shown above is the directory containing my custom scripts library in my Sky Drive folder.

    So what you want to do is automagically “replace” the contents of #1 with #3 – SQL will take care of keeping #2 in sync (I hope…).

    To do this you need to create a symbolic link from #3 to #1.  To learn about symbolic links, read this.  They are essentially shortcuts… but on steroids.  Here’s the command I use to setup my environment:

    cd "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\SqlWorkbenchProjectItems"
    ren Sql Sql_Old
    mklink /D Sql "C:\My Stuff\SkyDrive\Scripts\SQL\SSMS_Templates\Sql"

    Obviously your paths (and username) will differ, so make the appropriate changes before trying this yourself.  Please be sure about what you’re doing (never just run something from the Internet without 100% understanding what it does). I take no responsibility if you somehow manage to brick your system – YMMV, etc, etc.

    All going to plan, you’ll now have SSMS using your own source of templates. πŸ™‚

    Cheers,
    Dave

  • What’s in your toolbox?

    Toolbox Lock - by Jenn Durfey

    I’ve had a few weeks off work recently, during which time I decided to tidy up (or attempt to anyway) my collection of “utility scripts”.  This consists of about 95% regular T-SQL scripts, with the rest being a mixture of PowerShell scripts, batch files, etc.

    This made me wonder how other people managed their collections, and whether their are better ways (or tools) to catalogue and easily retrieve useful scripts and snippets?

    What I do

    My solution is to use the built in SQL Server Management Studio Template Explorer.  I found a few good blog posts explaining where the templates are stored, and some different ways of getting the most out of them (for example, I went down the route of creating symbolic links so I could have one central set of scripts stored on my Skydrive, which I have access to from any computer).

    I was thinking about taking this one step further; I’m the database team lead at work, and it might be useful to collaboratively compile a list of scripts that each of us find useful/indispensable, which we could then add to our source control repository.  We could then each have symbolic links to this repository on our own computers, meaning the whole team would automatically have access to the latest versions of our “ΓΌber team toolbox” scripts.

    What’s in my toolbox?

    My SSMS Templates

    I’ve got a bunch of stuff… and I’ve still got a lot to categorise and move into my templates folder, but it’s a mix of some pretty well known utility scripts from some equally well known “SQL personalities”, as well as a lot of stuff I’ve written over the years and tucked aside for a rainy day, or scripts that I regularly need for the applications that we support.

    My “well known” utility scripts currently include:

    I have others that fall into this category (e.g. some queries from Glen Berry) that I’m still tidying up and organising.  The SQLServerPedia site also has a list of useful scripts which I’ve bookmarked for later follow-up.

    What else is there?

    Well, if you don’t think using templates is going to work for you, then there are a few other options (although not as many as I would’ve thought – hence the reason for this post)…

    Snippets

    I think of snippets as mini, or “in-line” templates.  The reason being most snippets are fragments of a larger script – for example you can have a snippet to insert a common stored procedure header block that you always use, or the syntax for a cursor declaration.  My templates tend to be more full-featured scripts, but I’m sure these could be stored as snippets too.  Here’s an article on snippets, including how to create your own.

    Talking about snippets – it’s easy to confuse the built-in SSMS snippets (which is what I was talking about above) with those included in Mladen PrajdiΔ‡’s very cool SSMS Tools Pack add-in.  In SSMS Tools Pack they’re more like fully customisable shortcuts to code snippets.  This means you don’t need to have an extra window open to select the snippet, you can just (for example) type ssf and hit enter, and it expands out to SELECT * FROM automagically. πŸ˜‰

    SQL Scripts Manager

    This is a free tool from Red Gate, which to be honest I haven’t played with very much yet (it’s still on my to-do list).  It seems to offer some cool features (like tagging scripts, a list of authors, etc), and comes bundled with a range of very useful scripts to get you started.  Here’s a write-up on it.

    I’ll definitely take a closer look at it when I get a chance – I’m interested to see where it stores the scripts (i.e. whether I can plug it into a central source control repository), and also whether there is any SSMS integration (which would be way cooler than just an external app).

    Good ol’ Explorer

    I’m guessing this is still the most common method; just putting a bunch of snippets and scripts into a directory (or, if you’ve got some semblance of order, perhaps a categorised series of directories).

    If this works for you (as it did me for many years), and you can still easily find what you need, then I guess there’s no real reason to change. πŸ˜‰

    What do you use?

    So, what method do you use to keep your scripts library in order, and do you have any other cool scripts you’d recommend I add to my library?  I’d love to hear from you via the comments section below.

    Cheers,
    DB Dave

  • SQL script of HTML status codes

    HTML Codes SQL Script

    Bit of a random post; I couldn’t find anything similar online, so created this script and thought I’d share it in case anyone randomly needs a lookup/dimension table of HTML status codes. All pulled directly from Wikipedia. πŸ™‚

  • Combining different database technologies

    Bike and a Bunny
    Bike and a Bunny

    Well the past month or two have been “busy”; I bought an old motorbike and restored it (win!), I sold my main motorbike and bought a new one (bigger win!), I then crashed it (not badly, but enough to ruin my day – boo!), I got the repaired bike back 4 weeks later (yay!) – and that’s just the 2-wheeled events, not the several dental surgeries my 7yo daughter’s needed, or the old “should-we-buy-a-new-house” gem. Phew…

    Of course alongside the above events, work has been as busy as ever. I’m trying to figure out if it’s actually possible for it to be getting busier, when a year ago I thought it was already crazy-busy. Anyway, we’ve got a number of slightly more meaty projects on the go involving major architectural changes, upgrades, migrations, etc – which are stressful but more rewarding than most normal BAU work.

    Anyway – getting to the point of this post, one of the things I’ve been thinking about on the side (to some extent) has involved some NoSQL technologies. Well, one so far, in the form of Redis. Nothing concrete so far, just a VM on my laptop that I’ve been playing with.

    This got me thinking (a dangerous event at the best of times); is there a method of efficiently transferring data between disparate database systems, such as SQL Server and Redis, other than writing higher level applications to handle the ETL process. I mean, that obviously works (and maybe I just don’t understand enough about how people currently do this) but it seems to me like there should be a more efficient, “lower level” method of pumping a stream of data out of SQL and into Redis (for example). Could a CLR procedure fill the gap here perhaps?

    The reason I was playing with this idea in the first place was related to a few bits of functionality which are sort of related; search autosuggest, a recommendation engine, and a context sensitive spell checker. All of these require massive sets of fairly narrow data (i.e. key-value pairs) that need to be queried in a predictable manner, very very quickly. All of these are actually already implemented using SQL Server, and handle some not-to-be-sneezed-at loads as it is.

    So SQL Server obviously works to an extent, and performance can be increased significantly by using solid state storage (SSDs or cards like the FusionIO range), or even further by using system memory (via some kind of ram drive software). The data itself isn’t mission critical, so redundancy isn’t as crucial, meaning volatile storage can be used.
    But at some point it becomes a lot more difficult to scale SQL to handle increasing load (financially and practically), which is where I think solutions like Redis, MemCacheDB, and quite a few others fit the bill perfectly.

    This is just one example where a key-value store makes sense (to me at least), although there are of course other scenarios where you might need a document store instead (like MongoDB) or the Map/Reduce batch-processing power of something like HBase. In fact, Microsoft already has a Hadoop (or is that “an Hadoop…“?) connector, so I wonder if we will eventually have connectors for other systems as well?

    I guess for now I’m resigned to brushing up on my horribly dusty and inadequate .Net dev skills in order to try out my whacky grand plans of disparate databases talking to each other nicely like good little children. Any dev’s feel like giving me a hand? :-p

    One random, rambling post; check. πŸ˜‰

    Cheers
    Dave

  • Putting Humpty together again

    Though I’d take the opportunity (i.e. defrosting my toes on my heated blanket) to post a progress report on my KH125 rebuild project. I’m doing so from my phone, so please excuse me if the formatting turns out less than ideal.

    Continuing my recent non-SQL-related post trend, here are some photos, and a bit of a brain dump (or running commentary), regarding a 1980 Kawasaki KH-125 A4 rebuild/refurb that I’m busy with.

    At the beginning of the weekend I had the frame clean and ready for paint, so I coated it and a few other parts of the chassis with some high temperature epoxy based enamel. I didn’t particularly need the high temp properties of this paint, but have used it before and found it to be easy to use (i.e. gives a good finish) and very durable.

    20120709-233910.jpg
    20120709-233948.jpg

    Fast forward through a bunch of waiting for paint to dry, then a second coat, then more waiting, then realizing that the outside temperature was too cold for the paint to cure properly and so putting the frame inside on the dining room table (yes, really). Earlier today that meant I had a nicely dried frame ready for some assembly.

    20120709-234458.jpg

    I had an old computer desk that I quickly converted into a make-shift bike stand, quite successfully actually. Once I’d set my work space up, things started coming together…

    20120709-234655.jpg
    20120709-234720.jpg
    20120709-234737.jpg
    20120709-234754.jpg

    At around this time (11pm’ish), I realized that I couldn’t really feel my toes anymore, and a quick check of the thermometer confirmed a chilly 4 degrees inside my garage. So I called it quits in favour of a warm bed.

    Overall I didn’t hit too many snags, although I do have a special hate reserved just for the o-rings on the swing arm bushings (they didn’t feel much like going back in), and I also wish I’d listened to my wife (don’t tell her I said that!) and more carefully labelled some of the nuts and screws I so hastily removed when stripping the bike down. Meh, I’m sure I’ll figure out where they all go eventually. And if any are left over, well we’ll just call it a weight saving exercise. πŸ˜‰
    The wife says that’s fine as long as I then ride the bike first. No faith…

    So this is where I left her; pretty much all that’s left to do is mounting the rear wheel, brake, air box, and seat.

    20120709-235844.jpg

    All going well I’ll try firing her up tomorrow. I don’t hold out much hope though as I expect I’ll first be spending a fair amount of time swearing at fine tuning things like the carbs, oil pump, clutch setup, etc. Let’s hope nothing blows up, ‘ey?!

    πŸ˜‰

  • Elbow grease

    Why do they call it elbow grease?  I’m going to have to google that now before my laptop’s battery dies on me… one minute please.  Right, that was less interesting than I expected…

    Anyway, I….

    Sorry about that, just took a little break to let the scary earthquake pass – sheesh!  Not fun.

    Back to the point; elbow grease. I’ve been using a lot of it lately.  In my previous post I showed off the latest addition to my garage; a mighty 1980 Kawasaki KH 125.  I’ve always enjoyed “spannering” in the garage, but this is the first time I’ve bought something specifically as a project.  I’ve enjoyed it a lot more than I was expecting, and more surprisingly so has my wife!  It’s very relaxing coming home after a busy day wrangling databases, and just sitting for a few hours disassembling a carburettor, or polishing a chrome wheel.  On a few evenings we put the girls to bed, and my wife then joins me in the garage with a couple coffees, and helps polish, unscrew, clean, etc.  We actually get a chance to talk a lot more than we otherwise would sitting in front of the TV.

    Here’s some of my wife’s recent handy work:

    All very shiny! πŸ™‚ Now that took some serious elbow grease.

    I whipped the engine block out a few nights ago as well, so my work bench is getting a little crowded now.  One reason I chose this specific bike to restore was that it’s pretty bloody simple, so it only took me half an hour or so to strip, clean and rebuild the carb – which now takes pride of place in one of the many empty coffee cups.

    Now that the frame is bare, I can see that it’s thankfully in really good condition.  I’ve priced up getting it and the rear swing-arm bead blasted and powder coated, but it’ll cost more than the entire bike cost to begin with, so my wife and I (and probably the kids if I can bribe them) will need to get that elbow grease out again to clean and strip the frame back as much as possible.  Once it’s clean, then several coats of some good durable enamel should be plenty good enough for now.

    That’s probably enough for now.  The next steps are going to be cleaning up the engine block, replacing the spark plug and oil, and then attacking the frame to get it ready for paint.  Once the frame and a few other bits are done, then I can start the re-assembly.

    I’ll post updates to my progress as I go.  If you really couldn’t care less, and just want stuff related to SQL Server, then check out the SQL specific category instead.  I’ve created a “Wheels” category to dump this sort of stuff into for those who like getting a little grease under their finger nails. πŸ˜‰

    Cheers,
    Dave