Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL2000 SQL-server-2005 SQL , +
Hi all
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.
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 25-Apr-12 0:35am
Edited 25-Apr-12 0:57am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
bhagirathimfs at 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?
Uma Shankar Patel at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
bhagirathimfs at 25-Apr-12 6:43am
   
Sry didn't get anything.
can u please elaborately explain this.
 
Thanks in advance

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

  Print Answers RSS
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 185
2 jlopez788 144
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,559
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 25 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100