Reputation: 57
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 application 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
Upvotes: 0
Views: 858
Reputation: 9124
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.
Upvotes: 2
Reputation: 24236
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.
Upvotes: 2
Reputation: 13091
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.
Upvotes: 1