Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all
SQL
SELECT EMP_ID,EMP_NAME,EMP_DOJ,EMP_SALARY FROM EMP WHERE EMP_ID = 76562;

This the general approach.

We can write this in parametrized way i.e.
SQL
SELECT EMP_ID,EMP_NAME,EMP_DOJ,EMP_SALARY FROM EMP WHERE EMP_ID = @EMPID;
mycommand.Parameters.Add("@EMPID",76562);


Which one is better and why?
and which one is faster(take less time to execute)
I am using MYSQL database.
Thanks in advance.
Posted
Updated 25-Apr-12 0:57am
v4

The perforamnce of query is depend on Exceution Plan.
I think to write parametrized query will be good practice because it helps to prevent from SQL Injection 1
Sql Injection 2
if you are taking input from user.
 
Share this answer
 
Comments
bhagirathimfs 25-Apr-12 6:59am    
Thanks Uma Shankar Patel.

one query
If that is not taken from the end user which one i should write.Which one is more faster?
uspatel 25-Apr-12 7:03am    
check you both query's by clicking dispaly execution plan in SQL server mgmt studio.
Check response time of both,You can find which is best.
Hey,

If you use this query into a Sql SP-

Then would be play better perform because using into SP it works a pre compile query.

We just call SP with param each time.
 
Share this answer
 
Comments
bhagirathimfs 25-Apr-12 6:43am    
Sry didn't get anything.
can u please elaborately explain this.

Thanks in advance
the first approach is better. Please refer to http://technet.microsoft.com/library/cc966419[^] then search for a subtitle 'Avoid use of local variables in queries'

hth,
Foxyland
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900