我们的存储过程包含开发人员注释和标题,并且作为部署过程的一部分,我们希望将这些注释从客户副本中删除。有没有在SQL Server 2005或其他工具中实现这一点的方法?删除SQL注释
Q
删除SQL注释
2
A
回答
1
您可能要检查了这一点:
Remove Comments from SQL Server Stored Procedures。
注意:这不处理以 - 开头的注释,SQL Server允许。否则,我会询问让开发人员编写一个简短的过滤器应用程序,通过流读取文本,然后删除评论。或者自己写。
0
我假设您将过程定义保存到文本或.sql文件中,然后再进行版本控制。你总是可以使用像notepadd++这样的东西来找到/替换你想要的字符串,然后将它们作为生产/客户标签提交。这不是优雅的,而是一种选择。我不知道任何第三方工具,我的谷歌搜索返回的结果与其他发布的海报相同。
2
我使用一个名为WinSQL(非常方便,强烈推荐)的SQL工具,它有一个“本地解析注释”选项。
我并没有亲自使用它,但是当我运行构建我的存储过程的脚本时,我意外地发现了它,并且它将它们从数据库中的proc源中清除。 :-)
即使免费版本也有这个选项。
2
不知道它是否适合,但您可以使用WITH ENCRYPTION选项来隐藏整个内容。您的最终用户是否需要查看/修改任何程序?
1
最后我写我在C#
2
此选项不可用时,有人问,但在2012年SQL,我们现在可以使用SQL Server自身的解析器来帮助我们自己SQL comment remover。 Removing Comments From SQL
0
您可以使用C#中的正则表达式删除注释,如here所述。它适用于行注释,块注释,即使块注释嵌套,并且它可以正确识别并忽略注释分隔符,当它们位于文字或括号内的命名标识符内时。
1
有点迟到了,但在整个案件别人绊倒......
CREATE FUNCTION [usf_StripSQLComments] (@CommentedSQLCode VARCHAR(max))
RETURNS Varchar(max)
/****************************************************************************************
--######################################################################################
-- [email protected] -- Some count sheep. Some code. Some write code to count sheep.
--######################################################################################
--#############################################################################
-- Sample Call Script
--#############################################################################
Declare @SqlCode Varchar(Max)
Declare @objname varchar(max) = 'sp_myproc'
select @Sqlcode = OBJECT_DEFINITION(t.OBJECT_ID)
from sys.objects t
where t.name = @objname
select dbo.ssf_StripSQLComments(@Sqlcode)
****************************************************************************************/
AS
BEGIN
DECLARE @Sqlcode VARCHAR(MAX) [email protected]
Declare @i integer = 0
Declare @Char1 Char(1)
Declare @Char2 Char(1)
Declare @TrailingComment Char(1) = 'N'
Declare @UncommentedSQLCode varchar(Max)=''
Declare @Whackcounter Integer = 0
Declare @max Integer = DATALENGTH(@sqlcode)
While @i < @max
Begin
Select @Char1 = Substring(@Sqlcode,@i,1)
if @Char1 not in ('-', '/','''','*')
begin
if @Char1 = CHAR(13) or @Char1 = CHAR(10)
Select @TrailingComment = 'N'
Else if not (@Char1 = CHAR(32) or @Char1 = CHAR(9)) and @TrailingComment = 'N' -- Not Space or Tab
Select @TrailingComment = 'Y'
if @Whackcounter = 0
Select @UncommentedSQLCode += @Char1
select @i+=1
end
else
begin
Select @Char2 = @Char1
, @Char1 = Substring(@Sqlcode,@i+1,1)
If @Char1 = '-' and @Char2 = '-' and @Whackcounter = 0
Begin
While @i < @Max and Substring(@Sqlcode,@i,1) not in (char(13), char(10))
Select @i+=1
if Substring(@Sqlcode,@i,1) = char(13) and @TrailingComment = 'N'
Select @i+=1
if Substring(@Sqlcode,@i,1) = char(10) and @TrailingComment = 'N'
Select @i+=1
End
else If @Char1 = '*' and @Char2 = '/'
Begin
Select @Whackcounter += 1
, @i += 2
End
else If @Char1 = '/' and @Char2 = '*'
Begin
Select @Whackcounter -= 1
, @i += 2
End
else if @char2 = '''' and @Whackcounter = 0
begin
Select @UncommentedSQLCode += @char2
while Substring(@Sqlcode,@i,1) <> ''''
Begin
Select @UncommentedSQLCode += Substring(@Sqlcode,@i,1)
, @i +=1
end
Select @i +=1
, @Char1 = Substring(@Sqlcode,@i,1)
end
else
Begin
if @Whackcounter = 0
Select @UncommentedSQLCode += @Char2
Select @i+=1
end
end
End
Return @UncommentedSQLCode
END
相关问题
- 1. SecondarySort -OverrideError(删除注释)
- 2. 从mapView中删除注释
- 3. 如何删除XML注释
- 4. Scichart不能删除注释
- 5. Vim - 删除XML注释
- 6. 如何删除SQL Server 2016中的注释sys.sql_modules定义
- 7. SQL/Wordpress - 删除注释字段的查询
- 8. 我必须删除@Override注释吗?
- 9. 删除C样式多行注释
- 10. SED删除C程序注释
- 11. 删除文本框但保留注释
- 12. 从firebase删除注释数据
- 13. 删除注释时的问题
- 14. 从注释中删除页面引用
- 15. MKMapView没有正确删除注释?
- 16. 删除文本文件中的注释
- 17. 从MapView删除多个注释
- 18. 删除MKMapView注释导致泄漏
- 19. 处理XML文件会删除注释
- 20. 如何动画刚删除的注释?
- 21. FBAnnotationClustering在swift中删除注释
- 22. 在XML中删除注释android
- 23. 似乎无法删除任何注释
- 24. 删除JavaScript中替换的注释
- 25. xsl删除所有节点的注释
- 26. 使用IntelliJ删除源文件注释?
- 27. 从PDF中删除空注释
- 28. 从Modelica模型中删除注释
- 29. 删除Annotation一次删除随机数量的注释
- 30. Hibernate sql注释
请检查该【答案】(http://stackoverflow.com/a/33947706/3606250) – drizin 2015-11-29 19:57:00