【问题标题】:better approach for stored procedure存储过程的更好方法
【发布时间】:2011-05-04 07:00:58
【问题描述】:

我需要专家建议我应该为每个操作创建单独的存储过程,或者我应该为所有操作创建一个存储过程,如下例所示:

create proc proc_name
@mode int =0,
@othervariables

as
begin
if @mode =1
begin
insert operation
end

else if @mode =2
begin
update operation
end

else if @mode =3
begin
delete operation
end

else if @mode =4
begin
select statement
end
---- other operations
end

专家我真的需要您的宝贵意见。速度将是我网站的主要关注点。它们将减少插入/更新操作和每分钟数千次检索操作。

谢谢

【问题讨论】:

    标签: sql sql-server-2005 stored-procedures


    【解决方案1】:

    通常您应该创建单独的程序。

    您通常会根据操作使用不同的参数集,并且仅具有实际使用的参数的过程更易于使用和维护。

    您应该尽量避免在您的示例中使用像 mode 参数这样的幻数。使用描述性过程名称比参数中的数字更容易看到发生了什么。

    通过选择一种方法或另一种方法,您无法获得相关的性能提升。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多