SQL Server存储过程命名标准


这个标准蓝图的存储过程命名方法只适用于SQL内部,当创建一个新的存储过程,或者发现一个没有按照这个标准构造的存储过程,请使用这个标准。

  注意:如果存储过程以sp_为前缀开始命名,那么会运行的稍微缓慢,这是因为SQL Server将首先查找系统存储过程,所以我们决不推荐使用sp_作为前缀。

  句法:

  存储过程的命名有这个的语法:


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->[proc] [MainTableName] By [FieldName(optional)] [Action]
[ 1 ] [ 2 ] [ 3 ] [ 4 ]
  [1] 所有的存储过程必须有前缀'proc'。所有的系统存储过程都有前缀"sp_",推荐不使用这样的前缀因为会稍微的减慢。
  [2] 表名就是存储过程访问的对象。
  [3] 可选字段名就是条件子句。比如:procClientByCoNameSelect,procClientByClientIDSelect。
  [4] 最后的行为动词就是存储过程要执行的任务。

  如果存储过程返回一条记录那么后缀是:Select

  如果存储过程插入数据那么后缀是:Insert

  如果存储过程更新数据那么后缀是:Update

  如果存储过程有插入和更新那么后缀是:Save

  如果存储过程删除数据那么后缀是:Delete

  如果存储过程更新表中的数据 (ie. drop and create) 那么后缀是:Create

  如果存储过程返回输出参数或0,那么后缀是:Output

例子:

  一个仅仅返回一个输出参数的存储过程:


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->ALTER PROCEDURE procClientRateOutput @pstrClientID VARCHAR(6) = 'CABLE',@pstrCategoryID VARCHAR(6) = '',@pstrEmpID VARCHAR(6)='AC',@pdteDate datetime = '1996/1/1',@curRate MONEY OUTPUTAS-- Description: Get the $Rate for this client and this employee --         and this category from Table ClientRateSET @curRate = (SELECT TOP 1 Rate FROM ClientRate WHERE ClientID=@pstrClientID AND EmpID=@pstrEmpID AND CategoryID=@pstrCategoryIDAND DateEnd > @pdteDateORDER BY DateEnd)IF @curRate IS NULLSET @curRate =(SELECT TOP 1 Rate FROM ClientRate WHERE ClientID=@pstrClientIDAND EmpID=@pstrEmpID AND CategoryID='' AND DateEnd > @pdteDate ORDER BY DateEnd)RETURN
  过时的风格:


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->Select 'procGetRate' or 'sp_GetRate' Insert 'procEmailMergeAdd'
  推荐的风格:


Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->'procClientRateSelect' 'procEmailMergeInsert'


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3