In C# or any other similar languages, if we use a magic number, it is bad practice. How about SQL? I have seen this type of SQL a lot:
CREATE PROCEDURE ProcessOrder
@productTypeId INT
, @productName NVARCHAR(50)
AS
BEGIN
IF (@productType = 3) -- Electronic product type
-- Handle electronic
ELSE IF (@productType = 4) -- Other product type
END
The user call this with an ENUM which converted to INT. Assuming ProductType table (3, ‘Electronic’) exist.
What should be the best practice here?
You can always use functions.