Thursday, June 16, 2005

SQL Server Templates

Who knew.... For years, I've used Query Analyzer to created stored procedures, etc. At times, I've even used the Templates feature to give me a starting point, and found myself using find-and-replace to change the parametersplaceholders.

For example:

IF EXISTS (SELECT *
FROM sysobjects
WHERE name = N'[scalar_function_name,]')
DROP FUNCTION [scalar_function_name,]
GO

CREATE FUNCTION [scalar_function_name,]
([@param1, sysname, @p1] [data_type_for_param1,],
[@param2, sysname, @p2] [data_type_for_param2,])
RETURNS
...
I installed the Yukon (SQL Server 2005) CTP bits last night because I need to get caught up on that technology. I used the Management Studio today to perform some work on my current project (against a SQL 2000 database), and created a new stored procedure.

Management Studio displayed the same type of familiar template, but in the comments, it displayed "Use the Specify Values for Template Parameters command (Ctrl-Shift-M) to fill in the parameter values below".

What's this "Specify Values for Template Parameters" command? Must be something new, I thought. I hit Ctrl-Shift-M, and up pops this window with each parameter, allowing me to specify my own values. It's an automatic multi-value find-and-replace mechanism that's built in!

I opened up the old Query Analyzer, and lo-and-behold, that feature's always been there! It even has a command in the Edit menu. I'm pretty traditional, so I don't think that I'll ever use it, but it's good to know that it's available if I need it.