📄 61057.htm
字号:
<link href="./dzs_cs.css" rel="stylesheet" type="text/css" /><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> <tr> <td height="24" align="center" valign="bottom" class="d_font3">SQL Server存储过程命名标准</td> </tr> <tr> <td height="3" bgcolor="#E3E3E3"></td> </tr> <tr> <td> </td> </tr> <tr> <td class="d_font4"><P>这个标准蓝图的存储过程命名方法只适用于SQL内部,当创建一个新的存储过程,或者发现一个没有按照这个标准构造的存储过程,请使用这个标准。</P>
<P>注意:如果存储过程以sp_为前缀开始命名,那么会运行的稍微缓慢,这是因为SQL Server将首先查找系统存储过程,所以我们决不推荐使用sp_作为前缀。</P>
<P>句法:</P>
<P>存储过程的命名有这个的语法:</P>
<P>[proc] [MainTableName] By [FieldName(optional)] [Action]</P>
<P><BR>[ 1 ] [ 2 ] [ 3 ][ 4 ]</P>
<P>[1] 所有的存储过程必须有前缀'proc'。所有的系统存储过程都有前缀"sp_",推荐不使用这样的前缀因为会稍微的减慢。<BR>[2] 表名就是存储过程访问的对象。<BR>[3] 可选字段名就是条件子句。比如:procClientByCoNameSelect,procClientByClientIDSelect。<BR>[4] 最后的行为动词就是存储过程要执行的任务。</P>
<P>如果存储过程返回一条记录那么后缀是:Select</P>
<P>如果存储过程插入数据那么后缀是:Insert</P>
<P>如果存储过程更新数据那么后缀是:Update</P>
<P>如果存储过程有插入和更新那么后缀是:Save</P>
<P>如果存储过程删除数据那么后缀是:Delete</P>
<P>如果存储过程更新表中的数据 (ie. drop and create) 那么后缀是:Create</P>
<P>如果存储过程返回输出参数或0,那么后缀是:Output</P>
<P>例子:</P>
<P>一个仅仅返回一个输出参数的存储过程:</P>
<P>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1>
<TBODY>
<TR>
<TD class=code bgColor=#e6e6e6><PRE><P>ALTER PROCEDURE procClientRateOutput <BR> @pstrClientID VARCHAR(6) = 'CABLE',<BR> @pstrCategoryID VARCHAR(6) = '<All>',<BR> @pstrEmpID VARCHAR(6)='AC',<BR> @pdteDate datetime = '1996/1/1',<BR> @curRate MONEY OUTPUT</P><P>AS</P><P>-- Description: Get the $Rate for this client and this employee <BR>-- and this category from Table ClientRate</P><P>SET @curRate = (<BR> SELECT TOP 1 Rate <BR> FROM ClientRate <BR> WHERE <A href="mailto:ClientID=@pstrClientID">ClientID=@pstrClientID</A> <BR> AND <A href="mailto:EmpID=@pstrEmpID">EmpID=@pstrEmpID</A> <BR> AND <A href="mailto:CategoryID=@pstrCategoryID">CategoryID=@pstrCategoryID</A><BR> AND DateEnd > @pdteDate<BR> ORDER BY DateEnd<BR> )</P><P>IF @curRate IS NULL</P><P> SET @curRate =<BR>(<BR> SELECT TOP 1 Rate <BR> FROM ClientRate <BR> WHERE <A href="mailto:ClientID=@pstrClientID">ClientID=@pstrClientID</A><BR> AND <A href="mailto:EmpID=@pstrEmpID">EmpID=@pstrEmpID</A> <BR> AND CategoryID='<ALL>' <BR> AND DateEnd > @pdteDate <BR> ORDER BY DateEnd<BR> )</P><P>RETURN</P></PRE></TD></TR></TBODY></TABLE></P>
<P>过时的风格:</P>
<P>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1>
<TBODY>
<TR>
<TD class=code bgColor=#e6e6e6><PRE>Select 'procGetRate' or 'sp_GetRate' <BR>Insert 'procEmailMergeAdd'</PRE></TD></TR></TBODY></TABLE></P>
<P>推荐的风格:</P>
<P>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 align=center borderColorLight=black border=1>
<TBODY>
<TR>
<TD class=code bgColor=#e6e6e6><PRE><P>'procClientRateSelect' <BR>'procEmailMergeInsert'</P></PRE></TD></TR></TBODY></TABLE></P>
<P><FONT size=4>【相关文章】</FONT></P>
<UL type=disc>
<LI><A href="http://database.51cto.com/art/200711/60809.htm" target=_blank><U><FONT color=blue>如何实现SQL Server快速导入数据</FONT></U></A></LI></UL>
<UL type=disc>
<LI><A href="http://database.51cto.com/art/200711/60641.htm" target=_blank><U><FONT color=blue>使用SQL Server数据库嵌套子查询</FONT></U></A></LI></UL>
<UL type=disc>
<LI><A href="http://database.51cto.com/art/200711/60587.htm" target=_blank><U><FONT color=blue>把SQL Server数据库部署到远程主机环境</FONT></U></A></LI></UL><DIV align=right>【责任编辑:<A class=ln href='mailto:sunsj@51cto.com'>火凤凰</A> TEL:(010)68476606】</DIV></td> </tr> <tr> <td class="d_font4"> </td> </tr> </table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -