I need to retrieve some fields from a table that match a given ID. Currently, I build a sql statement
SELECT a, b, c
FROM d
WHERE id = @id
Then execute it using the DataReader.
I could also write a stored proc that takes the id as parameter.
I wanted to know which is more performance friendly.
EDIT: I am using a parameterized query, edited the question to reflect that.
They are usually going to perform pretty much the same.
Note that differences can arise when this is called very frequently; the SQL code has to be parsed (but not necessarily re-compiled if the statement is recognized as being cached) every time when it is sent whereas the SP is precompiled, but that cancause suboptimal choices of indexes because the statistics aren’t re-evaluated on each call.