A simple trick for “Block Comment” syntax in SSMS

  • Phil Parkin (7/10/2015)

    OK, I roundly disagree with your absolute statement:

    "Thus advocating the approach is improper."

    Here is a part of a setup script I wrote recently. I developed it on one environment, then moved to QA, Prod etc.

    --Verifications Framework

    -------------------------

    --Author:Phil Parkin

    --Created:2015-06-03

    --Script to be run on the ETL server

    --*** Initial set-up only. Do not run when the live tables have been populated – the data would be deleted ***

    --Config database

    --__________________________________________________________________________________________________________________________________________

    /*

    --#region Create the SSISConnStringVariable table

    use Config;

    go

    if object_id('cfg.SSISConnStringVariable', 'U') is not null

    drop table cfg.SSISConnStringVariable;

    create table cfg.SSISConnStringVariable

    (

    SSISConnStringVariableNameId int identity(1, 1)

    not null

    ,SSISConnStringVariableName sysname not null

    ,SSISEnvironmentName sysname not null

    ,constraint PK_SSISConnStringVariable primary key clustered (SSISConnStringVariableNameId asc)

    );

    create unique index ix_SSISConnStringVariableName on cfg.SSISConnStringVariable(SSISConnStringVariableName);

    --*/

    --#endregion Create the SSISConnStringVariable table

    --__________________________________________________________________________________________________________________________________________

    On my system, with SSMSBoost (which supports collapsible regions) installed, I see this as follows:

    So, when I am running the script in QA, for example, all I have to do is comment out the first /* to make this block 'active'.

    Why is this such bad practice?

    As opposed to simply setting a sentinel variable and having an IF statement that only runs that section of code if the sentinel value is true? I.e. IsInitialConfig = True/False

    Or better yet, create/use an SSIS "install" package that is set only to do the initial config stuff on the first run.

    Don't even get me started on using CLR code in T-SQL work...

  • Something similar can be done in PowerShell

    Compare:

    <# header

    # comment

    Write-Host "uncommented"

    #>

    Write-Host "outside of comment"

    with

    #<# header

    # comment

    Write-Host "uncommented"

    #>

    Write-Host "outside of comment"

  • No comment.

    😉

  • I begin the block with [font="Courier New"]/*Dbg [/font]for debug code and [font="Courier New"]/*Rls[/font] for release code. That way I can search and replace [font="Courier New"]--/*Dbg [/font]with [font="Courier New"]/*Dbg [/font]to disable all the debug code at once and vice versa to enable.

  • GoofyGuy (7/10/2015)


    No comment.

    😉

    #<#

    # no comment ;-)

    Write-Host "no comment"

    #>

  • Thank you! great idea and very usefull 🙂

  • Thanks for the interesting post.

    Genuine question to someone who uses this method frequently (without trying to sound argumentative):

    Do you find this more useful than just highlighting the block and clicking the line comment/uncomment button? Or highlighting the block and pressing CTRL-K + CTRL-C or CTRL-K + CTRL-U?

  • Ross.M (7/13/2015)


    Thanks for the interesting post.

    Genuine question to someone who uses this method frequently (without trying to sound argumentative):

    Do you find this more useful than just highlighting the block and clicking the line comment/uncomment button? Or highlighting the block and pressing CTRL-K + CTRL-C or CTRL-K + CTRL-U?

    Yes indeed.

    Imagine this:

    --DELETE X

    --From X

    --Where Id = 12

    If you are working quickly, it is so very easy to miss the third line when selecting ... After pressing F5, the immediate sinking feeling is not good at all.


  • I've accidentally left debug code in, only to have it discovered after it went to production (they can't test everything).

  • This was removed by the editor as SPAM

Viewing 10 posts - 46 through 54 (of 54 total)

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