Category: SQL Server

  • Head in the clouds

    Head in the clouds

    Wow – 2 years and 4 days with no posts.  What a slacker…

    Anyway… I’ve been busy doing a few things in that time.  The most relevant probably being that I moved on from Trade Me near the end of 2014, and now work for Timely.  This is a small company started a couple of years ago by some guys who I used to work with at Trade Me, and we offer an online booking/scheduling system for SMB’s around the world.

    The interesting change for me from a technical perspective is that Timely is entirely based in “the Cloud” – or Microsoft Azure to be specific.  We have a blog post here which explains our systems at a high level (and even includes a Visio diagram put together by yours truly). πŸ™‚

    That’s already a little out of date though… that’s one of the things about IaaS and PaaS; it’s very easy to move quickly.  One minute there’s nothing, an hour later you’ve spun up a new SQL Server virtual machine with a couple extra data disks, and configured Reporting Services!

    This is awesome in that you can go from “Hey, I’ve got this cool idea!” to deployed into production in days (or even hours).  Proof-of-concept systems can be spun up and shut down with minimal effort, and Microsoft are pretty good these days at releasing frequent updates to Azure functionality; meaning there’s always fresh temptation to try out the latest beta-features.

    It can also be bad though. If it’s easy to spin up new servers and services, you’ll do it more often, and then you’ve got to manage them (oh yeah, and pay for them). So I’m finding myself getting elbow-deep in PowerShell more than I ever have before in order to script and automate things as much as possible.  Might not seem necessary when you’ve got 1 or 2 servers, but before you know it you’ll have half a dozen or more. πŸ˜‰

    Anyway, I’ll leave it at that for now since I’ve got a few posts lined up to cover some of these topics in more detail.

    Cheers,
    Dave

  • SQL Server version information from build numbers

    SQL Server version information from build numbers

    Just a quick post in case anyone else finds this useful; for a report I’ve created, I wanted to have SQL Server versions displayed in a nice, readable form, rather than the usual build number format (e.g. 11.0.3128.0).

    Server dashboard report

    So I found the very useful SQL Server Builds page (thanks to whoever maintains that), and proceeded to write a function which accepts the build number, and spits out a friendlier “version string”, down to the service pack and cumulative update level of resolution. (I didn’t need anything lower than that, but you could easily add it in yourself).

    Here’s the file, feel free to download, use, hack to pieces, etc. πŸ˜‰

    function

    Cheers,
    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