Analyzer

  • Hello Sql!

    I am tring to utilize the analyzer more often now days so that i may become better at writing procedures. I have noticed that the Analyer does not have a wizzard, (The enterprise manager does, (For querrys only))I am really wanting to learn to work with the templates in The Analyzer,, just looks like a much more powerful aproach..

    Below is a simple Basic template (as it says ~) and this is where i am confornted with all of this new syntax.

    I do know from my question the other day that the N' is for unicharters,, but the u' is a new one,,, and the way the structure of the querry is unique.. Like every where i look there is a reference to SysName..... What is up with that word every where... And can someone that works with this alot give me any pointers on what is what with this template below,,,, (as in what may be useful and what is not)

    Thanks,

    Erik..

    -- =============================================

    -- Create table basic template

    -- =============================================

    IF EXISTS(SELECT name

       FROM   sysobjects

       WHERE  name = N'<table_name, sysname, test_table>'

       AND   type = 'U')

        DROP TABLE <table_name, sysname, test_table>

    GO

    CREATE TABLE <table_name, sysname, test_table> (

    <column_1, sysname, c1> <datatype_for_column_1, , int> NULL,

    <column_2, sysname, c2> <datatype_for_column_2, , int> NOT NULL)

    GO

     

    Dam again!

  • The format for the replaceable parameters in the templates is,

    < parameter name , datatype , example data or default value >

    The 'sysname' that is referred to in the templates is system-supplied user-defined data type for nvarchar(128).

    Templates like these are extremely helpful when your creating a whole pile of stored procedures, or you want to standardise the way the stored procedures are layed out. I use this one pretty regularly,

    IF EXISTS (SELECT name FROM sysobjects 
                WHERE name = N'<procedure_name, sysname, usp_procname>' 
                    AND type = 'P')
        DROP PROCEDURE <procedure_name, sysname, usp_procname>
    GO
    CREATE PROCEDURE dbo.<procedure_name, sysname, usp_procname>
    /*************************************************************************
    FILENAME: 
        <procedure_source, sysname, full pathname to source code>
    SQL SERVER OBJECT NAME: 
        dbo.<procedure_name, sysname, usp_procname>
    AUTHOR:
        <author_name, sysname, Phillip Carter>
    DATE WRITTEN:
        <authored_date, datetime, 14 Aug 2004>
    PURPOSE:
        <procedure_purpose, varchar, Business problem to solve>
    ACTIONS:
        <procedure_actions, varchar, HOW Business problem is solved>
    INPUTS:
        <procedure_inputs, varchar, What inputs are required>
    OUTPUTS:
        <procedure_outputs, varchar, What outputs is produced>
    MODIFICATION HISTORY
    DATE  PERSON  REASON
    ----  ------  -----------------------------------------
    dd/mm/yyyy Who   what, why
    *************************************************************************/
        <@param1, sysname, @p1> <datatype_for_param1, , int> = <default_value_for_param1, , 0>, 
        <@param2, sysname, @p2> <datatype_for_param2, , int> = <default_value_for_param2, , 0>
    AS
    BEGIN
        SET NOCOUNT ON
        SET DATEFORMAT dmy
    END
    GO
    

    --------------------
    Colt 45 - the original point and click interface

  • Thank you for the reply!

    I will take the time to study up on this

    Erik..

    Dam again!

  • If you type CRTL-SHIFT-M or select Edit - Replace Template Paramters on the menu, Query Analyzer will pop up a window for you to enter a replacement value for each parameter.  You can use the same notation to put replacable elements in your own scripts, or create your own templates.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply