编写长存储过程是否是糟糕的数据库设计和编码风格的标志?

发布于 2024-09-10 17:36:38 字数 210 浏览 0 评论 0原文

我遇到过一个人,他声称自己已经在 Sql Server 中写入了超过 5000 行存储过程。那个长存储过程实际上是必需的吗?或者这是糟糕的数据库和编码设计的标志?我真的很担心。在我的一个基于保险的实时项目中,我从未在存储过程中编写过超过 100 行的代码,该项目必须处理美国协议和补充。顺便说一句,他在吹嘘自己好像写了这么长的存储过程做得很好。

预先感谢:)

等待您的回复。

I've met one person who claims he has wrote to over 5000 lines of stored procedure in Sql Server. Is that long stored procedure actually required ever? Or is it sign of a bad database and coding design? I am really worried. I never wrote anything long than 100 lines of code in Stored Procedure in one my live projects based on Insurance which had to deal with U.S Acords and Supplements. Btw, he was boasting as if he did some great job writing such long stored procedure.

Thanks in advance :)

Waiting for your replies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惟欲睡 2024-09-17 17:36:38

根据我个人的经验,有几个条件迫使你编写这么长的存储过程,这是我现在记得的两个条件

  • 糟糕的数据库设计(正如你已经提到的)
  • 一个非常复杂的计算公式非常复杂,报告等(例如人力资源 - 休假管理)

我不认为编写这么长的存储过程是一件好事,我个人认为这是一件很糟糕的事情,它表明数据库被搞乱了,计划不够周密。

From my personal experience, there are several conditions that force you to write such a long stored procedure, these are 2 of the ones that I'm remembering right now

  • Bad database design (as you already mentioned)
  • A big complicated formula for calculating sth very very complicated, reports etc. (e.g. Human Resources - Leave Management)

I don't think that writing such a long stored procedure is a good thing, I personally think that it's a pretty bad thing, it shows that the database is messed up, not planned thoroughly enough.

傲世九天 2024-09-17 17:36:38

我不认为存储过程的长度是糟糕的设计或编码风格的标志。

我认为存储过程中的代码是糟糕的设计或编码风格的标志。

他本可以写

SELECT
*
FROM
TABLE
AS
t

“那可以增长得很快,正如你知道的那样,可以放在一行中,也许他认为它更具可读性”。

重点是,我不认为长度是确定存储过程好坏的一个很好的指标。您可能会编写一个 100 行存储过程,但它比 5000 行存储过程要差。

如果我个人正在查看我的全新 5000 线存储过程,即使没有其他选择,我也会感到担忧而不是自豪。维持这一点将是一场噩梦。

但在您朋友的情况下,如果不知道存储过程执行什么操作或如何执行操作,就很难以任何方式进行评论。

I don't think the length of a stored procedure is a sign of bad design or coding style.

I think the code in a stored procedure is a sign of bad design or coding style.

He could have wrote

SELECT
*
FROM
TABLE
AS
t

That could grow pretty quickly, as you know that could fit on one line, maybe he thinks its more readable.

The point being, I don't think the length is a good metric to determine whether a sproc is good or bad. You can probably write a 100 line sproc which is worse than a 5000 line sproc.

If I personally was looking at my brand new 5000 line sproc, I would be worried and not proud, even if there was no other choice. Maintaining that will be a nightmare.

But in your friends case it's difficult to comment either way without knowing either what action the sproc performs or how it does it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文