还想看看人们的存储过程/功能等注释标题是什么样的(所以发布你的例子)......我只是真正看到了SQL Server Management Studio创建的内容但我对其他人的看法感兴趣...格式化,使用的字符,程序信息/细节等我认为真正使它们与众不同......
SQL Server Management Studio(版本9)存储过程注释标头默认值:
-- =============================================
-- Author: Name
-- Create date:
-- Description:
-- =============================================
答案 0 :(得分:40)
/******************************
** File:
** Name:
** Desc:
** Auth:
** Date:
**************************
** Change History
**************************
** PR Date Author Description
** -- -------- ------- ------------------------------------
** 1 01/10/2008 Dan added inner join
*******************************/
答案 1 :(得分:18)
--
-- STORED PROCEDURE
-- Name of stored procedure.
--
-- DESCRIPTION
-- Business description of the stored procedure's functionality.
--
-- PARAMETERS
-- @InputParameter1
-- * Description of @InputParameter1 and how it is used.
--
-- RETURN VALUE
-- 0 - No Error.
-- -1000 - Description of cause of non-zero return value.
--
-- PROGRAMMING NOTES
-- Gotchas and other notes for your fellow programmer.
--
-- CHANGE HISTORY
-- 05 May 2009 - Who
-- * More comprehensive description of the change than that included with the
-- source code commit message.
--
答案 2 :(得分:9)
我们使用这样的东西对我来说非常有用。
/*
Description:
Author:
Create Date:
Param:
Return:
Modified Date:
Modification:
*/
答案 3 :(得分:6)
-------------------------------------------------------------------------------
-- Author name
-- Created date
-- Purpose description of the business/technical purpose
-- using multiple lines as needed
-- Copyright © yyyy, Company Name, All Rights Reserved
-------------------------------------------------------------------------------
-- Modification History
--
-- 01/01/0000 developer full name
-- A comprehensive description of the changes. The description may use as
-- many lines as needed.
-------------------------------------------------------------------------------
答案 4 :(得分:5)
-- [why did we write this?]
-- [auto-generated change control info]
答案 5 :(得分:5)
set timing on <br>
set linesize 180<br>
spool template.log
/*<br>
##########################################################################<br>
-- Name : Template.sql<br>
-- Date : (sysdate) <br>
-- Author : Duncan van der Zalm - dvdzalm<br>
-- Company : stanDaarD-Z.nl<br>
-- Purpose : <br>
-- Usage sqlplus <br>
-- Impact :<br>
-- Required grants : sel on A, upd on B, drop on C<br>
-- Called by : some other process<br
##########################################################################<br>
-- ver user date change <br>
-- 1.0 DDZ 20110622 initial<br>
##########################################################################<br>
*/<br>
sho user<br>
select name from v$database;
select to_char(sysdate, 'Day DD Month yyyy HH24:MI:SS') "Start time"
from dual
;
-- script
select to_char(sysdate, 'Day DD Month yyyy HH24:MI:SS') "End time"
from dual
;
spool off
答案 6 :(得分:4)
我知道这篇文章很古老,但格式良好的代码永远不会过时。
我将这个模板用于我的所有程序。有些人不喜欢冗长的代码和注释,但作为经常需要更新自90年代中期以来未被触及的存储过程的人,我可以告诉你编写格式良好且评论很多的代码的价值。许多人的写作尽可能简洁,有时需要数天才能掌握程序的意图。通过简单地阅读它就可以很容易地看到一段代码正在做什么,但是如果没有适当的评论那就更难理解(有时甚至不可能)代码的意图。
解释它就像你正在通过它走一个初级开发人员。假设阅读它的人对它所处理的功能区域知之甚少,而对SQL的理解有限。为什么?很多时候,人们不得不查看程序来理解它们,即使他们没有意图或业务修改它们。
/***************************************************************************************************
Procedure: dbo.usp_DoSomeStuff
Create Date: 2018-01-25
Author: Joe Expert
Description: Verbose description of what the query does goes here. Be specific and don't be
afraid to say too much. More is better, than less, every single time. Think about
"what, when, where, how and why" when authoring a description.
Call by: [schema.usp_ProcThatCallsThis]
[Application Name]
[Job]
[PLC/Interface]
Affected table(s): [schema.TableModifiedByProc1]
[schema.TableModifiedByProc2]
Used By: Functional Area this is use in, for example, Payroll, Accounting, Finance
Parameter(s): @param1 - description and usage
@param2 - description and usage
Usage: EXEC dbo.usp_DoSomeStuff
@param1 = 1,
@param2 = 3,
@param3 = 2
Additional notes or caveats about this object, like where is can and cannot be run, or
gotchas to watch for when using it.
****************************************************************************************************
SUMMARY OF CHANGES
Date(yyyy-mm-dd) Author Comments
------------------- ------------------- ------------------------------------------------------------
2012-04-27 John Usdaworkhur Move Z <-> X was done in a single step. Warehouse does not
allow this. Converted to two step process.
Z <-> 7 <-> X
1) move class Z to class 7
2) move class 7 to class X
2018-03-22 Maan Widaplan General formatting and added header information.
2018-03-22 Maan Widaplan Added logic to automatically Move G <-> H after 12 months.
***************************************************************************************************/
除了这个标题之外,您的代码应该有很好的评论并从上到下进行概述。将注释块添加到主要功能部分,例如:
/***********************************
** Process all new Inventory records
** Verify quantities and mark as
** available to ship.
************************************/
添加大量内联注释,解释除最基本以外的所有条件,并始终格式化代码以提高可读性。缩进代码的长垂直页面比宽泛的短代码更好,这使得更容易看到代码块的开始位置,并在其他人支持您的代码时结束多年。有时宽的,非缩进的代码更具可读性。如果是这样,请使用它,但仅在必要时使用。
UPDATE Pallets
SET class_code = 'X'
WHERE
AND class_code != 'D'
AND class_code = 'Z'
AND historical = 'N'
AND quantity > 0
AND GETDATE() > DATEADD(minute, 30, creation_date)
AND pallet_id IN ( -- Only update pallets that we've created an Adjustment record for
SELECT Adjust_ID
FROM Adjustments
WHERE
AdjustmentStatus = 0
AND RecID > @MaxAdjNumber
答案 7 :(得分:3)
我们目前使用的标题如下所示:
---------------------------------------------------
-- Produced By : Our company
-- URL : www.company.com
-- Author : me
-- Date : yesterday
-- Purpose : to do something
-- Called by : some other process
-- Modifications : some other guy - today - to fix my bug
------------------------------------------------------------
在旁注中,我在SQL中放置的任何注释总是使用以下格式:
/ *评论* /
和过去一样,我遇到了一些问题:脚本编写(通过SQL Server)做了有趣的事情包装线和注释开始 - 注释掉了所需的SQL ....但这可能只是我。
答案 8 :(得分:1)
看看这是否符合您的要求:
/*
Notes on parameters: Give the details of all parameters supplied to the proc
This procedure will perform the following tasks:
Give details description of the intent of the proc
Additional notes:
Give information of something that you think needs additional mention, though is not directly related to the proc
Modification History:
07/11/2001 ACL TICKET/BUGID CHANGE DESCRIPTION
*/
答案 9 :(得分:0)
-- Author:
--
-- Original creation date:
--
-- Description:
答案 10 :(得分:0)
这是我目前使用的。三重注释(/ * / * / *)用于从对象定义中选取标题注释的集成。
/*/*/*
Name: pr_ProcName
Author: Joe Smith
Written: 6/15/16
Purpose: Short description about the proc.
Edit History: 6/15/16 - Joe Smith
+ Initial creation.
6/22/16 - Jaden Smith
+ Change source to blahblah
+ Optimized JOIN
6/30/16 - Joe Smith
+ Reverted changes made by Jaden.
*/*/*/
答案 11 :(得分:0)
这是我的首选变体:
/* =====================================================================
DESC: Some notes about what this does
tabbed in if you need additional lines
NOTES: Additional notes
tabbed in if you need additional lines
======================================================================== */