A simple trick for “Block Comment” syntax in SSMS

  • trboyden

    SSC Veteran

    Points: 263

    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...

  • Tim Moss

    SSC Rookie

    Points: 37

    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"

  • GoofyGuy

    SSCertifiable

    Points: 6029

    No comment.

    😉

  • aroggeband-815867

    SSC Rookie

    Points: 26

    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.

  • Tim Moss

    SSC Rookie

    Points: 37

    GoofyGuy (7/10/2015)


    No comment.

    😉

    #<#

    # no comment 😉

    Write-Host "no comment"

    #>

  • cbernabeu

    Grasshopper

    Points: 14

    Thank you! great idea and very usefull 🙂

  • RossRoss

    SSCommitted

    Points: 1646

    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?

  • Phil Parkin

    SSC Guru

    Points: 244807

    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.

    If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.
    See https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help/ for details of how to post T-SQL code-related questions.

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    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 55 (of 55 total)

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