Sunday, January 16, 2011

SQL Prompt Easter Egg

Having Red Gate's SQL Prompt installed with SQL Server Management Studio has saved me many headaches over the years of its use. It is extremely nice to type in a table name and see not only the column names, but also their data types and identification of primary keys. Another cool feature is the built-in short cut scripts that are included toward the bottom of the suggestion box. An example of these short cut scripts would be to type in the letters  cv and then hit enter and the following template for CREATE VIEW will appear:

CREATE VIEW
--WITH ENCRYPTION, SCHEMABINDING, VIEW_METADATA
AS
   SELECT /* query specification */
-- WITH CHECK OPTION
GO

These scripts are great, and on occasion rather humorous. Recently, I was writing an UPDATE statement that would update a derived and aliased set of data in . An example of such a statement is as follows:

UPDATE y
SET a.[FieldA] = b.[FieldB]
FROM
   (
       SELECT
           a.[FieldA]
           ,b.[FieldB]
       FROM
           [MyTableA] a
           INNER JOIN [MyTableB] b
               ON a.[PKA] = b.[PKB]
   ) y;

Upon typing the UPDATE y portion I hit enter and the expression "A A A A R G H !" appeared resulting in an unexpected burst of laughter.

Read more: Simple-talk