问题
I'm running SSMS 12.0.2000.8
If I use the SSMS query editor to create a stored procedure (such as the one below) the comments before BEGIN
are removed when I execute/save it:
CREATE PROCEDURE myproc
/* Say goodbye to this comment */
@var1 int -- this comment will disappear too
AS
BEGIN
/* This comment is safe */
select 'hello' -- this too shall endure
END
A colleague is running the same version of SSMS and has no such problems. If I execute one of his scripts using sqlcmd.exe
the comments get stripped then too. I presume there must be a global setting that I need to change but I have no idea where it might be.
回答1:
I was experiencing the same issue and found that it was caused by Tools -> Options -> SQL Server Object Explorer -> Scripting -> Convert user-defined data types to base types.
When this is "True" I lose my comment blocks. When "False" my comment blocks came back.
回答2:
After observing some other strangeness (namely with execute as caller
being added to my scripts), I did some Googling and discovered the answer:
delete \Users\[user]\AppData\Roaming\Microsoft\SQL Server Management Studio\12.0\sqlstudio.bin
WARNING: You will lose your current list of memorized SQL Servers/usernames/passwords.
回答3:
I tested this with SQL Server 2008 and SSMS 12.0.2000.8, and this was the result after "Script stored procedure as" - > "Create to" -> "Clipboard":
CREATE PROCEDURE [dbo].[myproc]
/* Say goodbye to this comment */
@var1 int -- this comment will disappear too
AS
BEGIN
/* This comment is safe */
select 'hello' -- this too shall endure
END
GO
Have you tried checking with sp_helptext if the comments are in the procedure before you use the scripting tool?
I also checked the options, can't find anything there related to comments, or stripping away anything like that.
来源:https://stackoverflow.com/questions/28624224/ssms-removing-pre-begin-comments-from-my-stored-procedures