SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Remove SQL Comments


Remove SQL Comments

Author
Message
Spinja
Spinja
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 10
Comments posted to this topic are about the item Remove SQL Comments
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39501 Visits: 38553
Just curious, why would you want to remove comments from your SQL code/scripts?

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Nate Schmidt
Nate Schmidt
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 166
Question: could this be combined somehow with Redgate's SQL Search tool. Or (alternately) with a stored procedure that searches for a specified text string. Goal here is to remove or ignore the 'false positives' that show up when I'm doing an impact analysis for an impending database upgrade. References to said database show up in the comments or documentation section of a sproc, and I'd prefer (perhaps optionally) that those non-programmatic references be ignore.
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28285 Visits: 39955
Lynn Pettis - Monday, April 3, 2017 3:22 PM
Just curious, why would you want to remove comments from your SQL code/scripts?

I've done this specifically when i'm searching the text of sys.sql_modules.definitions, looking for various things related to coding practices, but not references to objects.
specifically, i have a similar procedure that strips comments, and then also all whitespace.

now that text has no spaces,and i can search for coding patterns.
if I find "SELECTTOP1" in any cleaned definition, there is an excellent chance that someone is using an inline query to get one column value, which is executed on a per row basis. I use that to replace it with a proper join and group by to fix performance.
i can then check for exists /not exists for other things like whether "SETXACT_ABORTON" exists in the stripped clean Definition or not, and decide whether it should have been there..."NOCOUNTON" , "ASBEGIN" and so many other "better practices" that should exist but might be missing.

also it makes it a bit easier to search for whehter @TableVariables where used, and i might want to replace with #temp tables, and index hints like nolock or merge/loop joins, etc.


Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Spinja
Spinja
Valued Member
Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)Valued Member (52 reputation)

Group: General Forum Members
Points: 52 Visits: 10
Nate Schmidt - Thursday, April 13, 2017 6:33 AM
Question: could this be combined somehow with Redgate's SQL Search tool. Or (alternately) with a stored procedure that searches for a specified text string. Goal here is to remove or ignore the 'false positives' that show up when I'm doing an impact analysis for an impending database upgrade. References to said database show up in the comments or documentation section of a sproc, and I'd prefer (perhaps optionally) that those non-programmatic references be ignore.

That's a really good question. I can't speak to whether or not this can be incorporated into the Redgate tools. But searching database objects is the entire reason that I created this script in the first place. While Redgate's tools are awesome, the search tool isn't great when you need to run massive searches for many objects or many strings. So, when I have the function created, I can then write something like the code below. It's still possible to have false positives in something like a literal string, but this gets me 99% accurate results when searching for a certain table for example.


SELECT o.name, o.xtype
FROM sys.sql_modules m
INNER JOIN sys.sysobjects o
ON m.object_id = o.id
WHERE o.xtype IN ('P', 'V', 'TR', 'TF', 'FN', 'IF')
--AND m.definition LIKE '%Something%'
AND dbo.RemoveComments(m.definition) like '%something%'

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search