如何在SQL Server中更改存储过程时添加标头注释

时间:2015-08-21 13:08:51

标签: sql sql-server ssms sql-server-2014

我有一个存储过程,其中没有标题注释。我想添加它们,但每当我尝试时,它都不包括在内。

在SQL Server Management Studio I中:

1.右键单击我的存储过程,然后单击“修改”

USE [ABigDB]
GO
/****** Object:  StoredProcedure [dbo].[spDoWork]    Script Date: 21/08/2015 14:11:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spDoWork]
      @Id uniqueidentifier,
      @Session nvarchar(50),
      @XMLData xml
WITH EXECUTE AS OWNER
AS
BEGIN
--etc etc...
END

2.我将注释粘贴到存储过程上方并运行脚本:

-- Stored Procedure
--    Author:           Dave
--    Create date:      21/08/2015
--    Description:      Does Stuff      
--  Change history
--      07/08/2015  - Overlord - Done stuff
--      06/08/2015  - Kerrigan - Done more stuff
USE [ABigDB]
GO
/****** Object:  StoredProcedure [dbo].[spDoWork]    Script Date: 21/08/2015 14:11:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spDoWork]
      @Id uniqueidentifier,
      @Session nvarchar(50),
      @XMLData xml
WITH EXECUTE AS OWNER
AS
BEGIN
--etc etc...
END

3.当我修改相同的存储过程时,它显示为:

USE [ABigDB]
GO
/****** Object:  StoredProcedure [dbo].[spDoWork]    Script Date: 21/08/2015 14:11:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spDoWork]
      @Id uniqueidentifier,
      @Session nvarchar(50),
      @XMLData xml
WITH EXECUTE AS OWNER
AS
BEGIN
--etc etc...
END

那么如何让评论出现在那里?

2 个答案:

答案 0 :(得分:9)

我通过以下方式解决了这个问题:

USE [ABigDB]
GO
/****** Object:  StoredProcedure [dbo].[spDoWork]    Script Date: 21/08/2015 14:11:45 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- Stored Procedure
--    Author:           Dave
--    Create date:      21/08/2015
--    Description:      Does Stuff      
--  Change history
--      07/08/2015  - Overlord - Done stuff
--      06/08/2015  - Kerrigan - Done more stuff

ALTER PROCEDURE [dbo].[spDoWork]
      @Id uniqueidentifier,
      @Session nvarchar(50),
      @XMLData xml
WITH EXECUTE AS OWNER
AS
BEGIN
--etc etc...
END

答案 1 :(得分:1)

考虑将 添加 中的元数据用于您的过程,表格,列等,以便进行记录。

在查看数据库对象时,请参阅以下内容。

Is it possible to add a description/comment to a table in Microsoft SQL 2000+