Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Guest Editorial: In Praise of Templates


Guest Editorial: In Praise of Templates

Author
Message
Phil Factor
Phil Factor
Right there with Babe
Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)Right there with Babe (745 reputation)

Group: General Forum Members
Points: 745 Visits: 2937
Here is a sample of a customised template. There is a type of service table I use whose basic structure is pretty similar. I just delete the bits I don't need. It is far quicker than doing it by point 'n shoot.

-- =========================================
-- Create table template
-- =========================================
USE <DATABASE, SYSNAME, MyDatabase>
GO

IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name, sysname, sample_table>', 'U') IS NOT NULL
  
DROP TABLE <schema_name, SYSNAME, dbo>.<table_name, SYSNAME, sample_table>
GO
CREATE TABLE <schema_name, SYSNAME, dbo>.<table_name, SYSNAME, sample_table>
(
  
[<table_name, sysname, sample_table>_id] [int] IDENTITY(1,1) NOT NULL,
  
[creator] [varchar](80) NOT NULL CONSTRAINT [DF_<table_name, sysname, sample_table>_creator]  DEFAULT (USER_NAME()),
  
[insertiondate] [datetime] NOT NULL CONSTRAINT [DF_<table_name, sysname, sample_table>_insertiondate]  DEFAULT (GETDATE()),
  
[terminationdate] [datetime] NULL
    
CONSTRAINT PK_<schema_name, SYSNAME, dbo>_<table_name, SYSNAME, sample_table> PRIMARY KEY (<table_name, SYSNAME, sample_table>_id)
)
GO
-- Add description to table object
EXEC sys.sp_addextendedproperty
  
@name=N'MS_Description',
  
@value=N'<table_description_value,,Table description here>' ,
  
@level0type=N'SCHEMA',
  
@level0name=N'<schema_name, sysname, dbo>',
  
@level1type=N'TABLE',
  
@level1name=N'<table_name, sysname, sample_table>'
GO

-- Add description to a specific column
EXEC sys.sp_addextendedproperty
  
@name=N'MS_Description',
  
@value=N'primary key for the table' ,
  
@level0type=N'SCHEMA',
  
@level0name=N'<schema_name, sysname, dbo>',
  
@level1type=N'TABLE',
  
@level1name=N'<table_name, sysname, sample_table>',
  
@level2type=N'COLUMN',
  
@level2name=N'<table_name, sysname, sample_table>_id'
GO
EXEC sys.sp_addextendedproperty
  
@name=N'MS_Description',
  
@value=N'Date the record was created (automatic)' ,
  
@level0type=N'SCHEMA',
  
@level0name=N'<schema_name, sysname, dbo>',
  
@level1type=N'TABLE',
  
@level1name=N'<table_name, sysname, sample_table>',
  
@level2type=N'COLUMN',
  
@level2name=N'insertiondate'
GO
EXEC sys.sp_addextendedproperty
  
@name=N'MS_Description',
  
@value=N'Date for the termination of the record' ,
  
@level0type=N'SCHEMA',
  
@level0name=N'<schema_name, sysname, dbo>',
  
@level1type=N'TABLE',
  
@level1name=N'<table_name, sysname, sample_table>',
  
@level2type=N'COLUMN',
  
@level2name=N'Terminationdate'
GO
EXEC sys.sp_addextendedproperty
  
@name=N'MS_Description',
  
@value=N'Creator of the record' ,
  
@level0type=N'SCHEMA',
  
@level0name=N'<schema_name, sysname, dbo>',
  
@level1type=N'TABLE',
  
@level1name=N'<table_name, sysname, sample_table>',
  
@level2type=N'COLUMN',
  
@level2name=N'creator'
GO




Best wishes,

Phil Factor
Simple Talk
JoeA
JoeA
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 862
Is it possible that your Ctrl+Shift+M is being caught by another program?
I had this issue with a similar key sequence where an HP diagnostic (or update manager?) was catching them as a hot key - never made it down into the window that had actual focus.
I was able to override that sequence in the diagnostic S/W that was catching it.
Happened on a different machine than the one I'm typing into, so I don't have exact details.
george sibbald
george sibbald
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6326 Visits: 13687
JoeA (2/6/2009)
Is it possible that your Ctrl+Shift+M is being caught by another program?
I had this issue with a similar key sequence where an HP diagnostic (or update manager?) was catching them as a hot key - never made it down into the window that had actual focus.
I was able to override that sequence in the diagnostic S/W that was catching it.
Happened on a different machine than the one I'm typing into, so I don't have exact details.


was that aimed at me? I'm not having problems with it, just knew I wouldn't remember that combination of keys. Thanks anyway. I''l butt out now so things can get back on topic. Smile

---------------------------------------------------------------------
JoeA
JoeA
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 862
Nope, it was for Mr. Icocks, who said his key combo didn't work in SSMS 2008 Smile
icocks
icocks
SSC Rookie
SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)SSC Rookie (47 reputation)

Group: General Forum Members
Points: 47 Visits: 627
JoeA (2/6/2009)Is it possible that your Ctrl+Shift+M is being caught by another program?
I had this issue with a similar key sequence where an HP diagnostic (or update manager?) was catching them as a hot key - never made it down into the window that had actual focus.
I was able to override that sequence in the diagnostic S/W that was catching it.
Happened on a different machine than the one I'm typing into, so I don't have exact details.


was that aimed at me?


I believe it was aimed at me - for some reason Ctrl-Shift-M doesn't work for on my SSMS 2008 (though it was fine on 2005).
Something intercepting it sounds pretty plausible - will investigate.

Cheers,
Ian
george sibbald
george sibbald
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6326 Visits: 13687
JoeA (2/6/2009)
Nope, it was for Mr. Icocks, who said his key combo didn't work in SSMS 2008 Smile


Blush

---------------------------------------------------------------------
Charles Kincaid
Charles Kincaid
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1041 Visits: 2383
Good article Phil. I got to
when some shinier bead rolled into view
and it put me in mind of my cats. Smile

Then I saw your create table template. Sad

ATBCharles Kincaid
JJ B
JJ B
Old Hand
Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)Old Hand (327 reputation)

Group: General Forum Members
Points: 327 Visits: 2846
I'm a big fan of template use. They do save so much time, especially when you use templates for the big stuff like stored procedures. However, since I store all my procs, functions, views, etc. in MS Word documents, I use MS Word templates for my personal on-going use. It works great.

Here's a thought: One plus a Word template would have over SSMS would be that they can be stored on shared drives and used by a team instead of just one person.

Just sharing in case someone else is curious how that option works.
sgardner
sgardner
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 31
For most of my direct DB work I use SQuirreL SQL (http://www.squirrelsql.org/) It is a powerful database front end tool that runs across a wide range of databases. It has a rich set of plugins (that I don't take enough advantage of) as well as great out-of-the box functionality. It runs on Mac, Linux, Unix and windows. I find it much more productive than the MS Studio for quick database exploring and running ad-hoc scripts. It is really nice having the same tool no matter what machine and database I have to look at.
David.Poole
David.Poole
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3681 Visits: 3116
This time last year I wrote about how to share templates within a team of DBAs http://www.sqlservercentral.com/articles/System+Development+Life+Cycle/62933/

I use templates in conjuncton with the SQL Prompt and the combination of the two is greater than the sum of the parts.

What SSMS needs is a simple macro language. Something a bit more than SQLCMD mode but not as heavy weight as powershell.

What SQLPrompt needs is a few more constructs like their $CURSOR$ place marker.

$DATE.YMD$ would be useful as would $USER$, particularly as my company shares the SQL Prompt 3 Snippets.XML file between DBAs.

LinkedIn Profile

Newbie on www.simple-talk.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search