Hi,
Is there any difference between parameterized query and stored procedure query??
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Suthish NairRank #92 · 22.8K reputationPosted Apr 1, 2011, 9:12 AM EDT
Parameterized query is an T-SQL query that accepts parameters as same as from stored procedure or the DML statement you having.
To avoid SQL Injection Attacks we need to use Parameterized queries.
Even we can use Parameterized queries in Stored Procedure level. One of below link explains that.
Parameterized Query and SQL Injection Attacks
More
If you want more debate
More
I know its not to share junk of links, but above having different explanation and information.
Andrew FensterRank #983 · 2K reputationPosted Apr 1, 2011, 9:15 AM EDT
If you're asking about how the database deals with the call, and which is faster, it depends on the database. SQL Server and DB2 are about the same in the way they react, so I'll describe that.
Whenever you make a call, the database has to do a few things. It has to validate your call to make sure all the tables, columns, functions, etc. in your call really exist. It checks your syntax. It builds a plan to execute and then it executes it.
When you create a stored procedure, the database does a lot of this work in advance. It does all the validation and builds a plan. When you call the stored procedure, all it has to do is plug in your input parameters and run.
When you make a paremterized query, the database has to do everything right then: validate, check syntax, build the plan, etc. So the first time you make a parameterized call, it's much slower than calling a stored proc. HOWEVER, both DB2 and SQL Server then store the plan for a little while. So if you make the exact same paremeterized query, but with different input parameters, it runs much faster the second time. It runs at the same speed as a stored procedure. So if you're going to make the same call 100 times in row, it doesn't make much difference whether you do it with a stored procedure or parameterized query, at least, not as far as performance goes.
Andrew FensterRank #983 · 2K reputationPosted Apr 1, 2011, 9:46 AM EDT
I can't think of any way to write a parameterized query that's vulnerable to SQL injection.
Savita Joshi124 reputationPosted Apr 1, 2011, 5:29 PM EDT
I want to know when do we need to use Parameterized query and when to use stored procedure? How do we decide on this?
Suthish NairRank #92 · 22.8K reputationPosted Apr 2, 2011, 8:19 AM EDT