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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Apr 1, 2011, 1:12 PM
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.
Suthish NairPosted Apr 2, 2011, 12:19 PM
Savita JoshiPosted Apr 1, 2011, 9:29 PM
I want to know when do we need to use Parameterized query and when to use stored procedure? How do we decide on this?
Andrew FensterPosted Apr 1, 2011, 1:46 PM
I can't think of any way to write a parameterized query that's vulnerable to SQL injection.
Andrew FensterPosted Apr 1, 2011, 1:15 PM
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.