This post is a slight departure from the normal content and its part of what might be considered a challenge from the blog at http://thesqlagentman.com/2010/01/whose-blog-is-it-anyway/
I woke on Sunday morning in a panic, you know the way, it's like you accelerate from 0 to 100 mph in 2s, slowly the bedroom materialised around me. I made a mental note not to read my twitter feed just before going to bed, a dream featuring Live Nude Cats, that's the only place on the internet where a phrase like that would not be considered wholly out of place. I also know that I'm going to have flash backs of the horses all through the day, there is no natural way that they should have been in those positions. I guess as it was a dream then I can rest assured that none of them got hurt but I feel that there wouldnt have been a complete rescue. You know, like in the disaster movies where one of the most vulnerable of the victims gets left behind as the helicopter leaves the disaster site. Yup, I had a feeling that the pilot would be pleased with his work on the whole but as soon as he looks down he’s going to be very sad about the pony.
I can't claim to be at all creative but this dream was so vivid I wonder whether I could remember enough of it to pitch it as a TV series? After all, as we are getting more and more TV channels the quality of the content is dropping off a cliff. Who could I ask? It would need to be someone with enough clout to carry the whole project through, Steven "Of course a forth Indian Jones is a good idea" Spielberg or I could just ask George “Let’s Have Padme Die Of A Broken Heart Instead Of Anakin Crushing Her To Death” Lucas, he hasnt been too busy recently.
In realityI understand this is unlikely, so, how can we do this? May be by simply using some magical tool, library, or bong? No, we need to ... put it in a blog.
I guess there isnt so much to tell about this dream, maybe its a pity I’ve started, so I’ll finish!
Thursday, 21 January 2010
Monday, 18 January 2010
Writing TSQL faster with templates
SSMS Templates
The management tools that come with SQL Server are the way that most DBAs access and administer their database environment. SSMS has plenty of shortcuts and times saving features, one of which is the use T-SQL templates. SSMS templates are accessed via their own menu and are stored in folders just like you would access files on a windows explorer window. SSMS comes with a whole load of templates ready to run but you can add to and alter these very easily.
Firstly, lets look at getting a template onto the query editor and running it successfully.
Right, open up an SSMS session and hit Alt + N (or Ctrl + N for SSMS for SQL 2005) to open a new TSQL editor window. Now its possible that you will have the templates toolbar ready to use already but hit Ctrl + Alt + T to make it active. Lets pick something simple to start with, open up the Database folder and drag the Create Database template over to your query editor page. Right, we have the text on the page but we have to do a little work before we can hit F5 or click Execute.
You'll see that there are sections of code inside < > brackets. These are SSMS template parameters, we need to take this code out and replace it with something specific to our environment in order to make the script parse and then execute successfully. We could swipe the parameter with our mouse but that could get tedious if we pop out a template with loads of them, its easier to just press Alt + Q, Alt + S (Ctrl + Shift + M for SQL 2005 and earlier). This brings up the parameter completion dialog for you.
Simply type the database name in the higlighted area and press Enter. Job done, it is now ready to run, the text that you entered in the parameters dialog has been put in three places and the script will now successfully create a database (with all the default options such as file locations that are set at server level) providing you have security on the server to execute this command.
The management tools that come with SQL Server are the way that most DBAs access and administer their database environment. SSMS has plenty of shortcuts and times saving features, one of which is the use T-SQL templates. SSMS templates are accessed via their own menu and are stored in folders just like you would access files on a windows explorer window. SSMS comes with a whole load of templates ready to run but you can add to and alter these very easily.
Firstly, lets look at getting a template onto the query editor and running it successfully.
Right, open up an SSMS session and hit Alt + N (or Ctrl + N for SSMS for SQL 2005) to open a new TSQL editor window. Now its possible that you will have the templates toolbar ready to use already but hit Ctrl + Alt + T to make it active. Lets pick something simple to start with, open up the Database folder and drag the Create Database template over to your query editor page. Right, we have the text on the page but we have to do a little work before we can hit F5 or click Execute.
You'll see that there are sections of code inside < > brackets. These are SSMS template parameters, we need to take this code out and replace it with something specific to our environment in order to make the script parse and then execute successfully. We could swipe the parameter with our mouse but that could get tedious if we pop out a template with loads of them, its easier to just press Alt + Q, Alt + S (Ctrl + Shift + M for SQL 2005 and earlier). This brings up the parameter completion dialog for you.
Simply type the database name in the higlighted area and press Enter. Job done, it is now ready to run, the text that you entered in the parameters dialog has been put in three places and the script will now successfully create a database (with all the default options such as file locations that are set at server level) providing you have security on the server to execute this command.
Labels:
SQL Server,
SSMS,
templates,
TSQL
Subscribe to:
Posts (Atom)