开发者

A stored procedure returning string values

开发者 https://www.devze.com 2023-03-25 20:31 出处:网络
I\'m wondering if this is a good practice or not. I have a database with a few stored procedures which I run using C# application.

I'm wondering if this is a good practice or not. I have a database with a few stored procedures which I run using C# application.

Is it a good practice to return messages from stored procedures which can directly be shown to the appl开发者_运维知识库ication user?

For example:

CREATE PROCEDURE CheckParam

@Param int,
AS
 BEGIN

IF (@Parem > 0)
 BEGIN              
    SELECT 'Parameter is greater than 0'
 END
ELSE SELECT 'Parameter is smaller than 0' 
END


It would generally be considered best practice to have the code layer set the message text as this allows future maintainers of the code to clearly follow the intended logic.


No it's not. It's an awful practice. What if you'll need to support multiple languages or multiple display formats. Beside that, when project gets larger you'll start being confused when some part of presentation logic resides on DATABASE!!! and some parts on client side. Just return the DATA from DATABASE and nothing more.


It would be easier if you had a better example; the one you used would certainly impose a level of performance overhead that I wouldn't be happy with!

Typically, SQL Functions are better suited to returning 'scalar' values. I suggest you get familiar with those.

0

精彩评论

暂无评论...
验证码 换一张
取 消