views:

94

answers:

5

If you have a stored procedure that deletes record in a table, do you have to put a return statement and why?

I have always never put a return statement, but I just saw a snippet that has a return statement.

Sample:

DELETE 
FROM TableName
WHERE TableId = @Id

RETURN
+6  A: 

No, an empty return statement is optional. The only time it would be required is if you needed to return a value from the procedure, then you would need to either create a result set with a select statement or return a value.

In cases like yours the return statement is purely optional.

Andrew Hare
Thanks you @Andrew.
Colour Blend
+3  A: 

I think you answered your own question:

I have always never put a return statement

A return statement is not required.

ck
+1  A: 

Not necessary. It just indicates that you have finished working on that particular stored procedure. Return statement is usually good in conditions

Sarfraz
+2  A: 

No, Return statement is not at all compulsary. if you need to get some value whether it is a datatable or any datatype then only you have to use return keyword.

Return can be used at the time of calling a stored procedure from another stored procedure

Shantanu Gupta
+1 for the variation in answer.
Colour Blend
A: 

I've always returned the number of records modified but it isn't required.

tmeisenh