Click here to Skip to main content
11,716,133 members (85,827 online)
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 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
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  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 599
1 Richard MacCutchan 280
2 Maciej Los 275
3 OriginalGriff 160
4 F-ES Sitecore 145
0 Sergey Alexandrovich Kryukov 1,003
1 Richard MacCutchan 430
2 CHill60 415
3 Maciej Los 399
4 OriginalGriff 385


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 25 Apr 2012
Copyright © CodeProject, 1999-2015
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