Witch query is more efficient??
CREATE TABLE [dbo].[tbl_test](
[ID] [int] NOT NULL,
[Title] [varchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_tbl_test] PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
SELECT ID, Title
WHERE (ID = 1) OR (Title LIKE '%abc%')
SELECT ID, Title
WHERE (Title LIKE '%abc%') OR (ID = 1)
I just want to know
Whether or not changing the order of columns in where clause can effect performance(using OR in where)?
comparing ID field is faster than the like statement on Title column. so if the first statement in OR is true next statement should not be checked..
I think Query1 is faster as Like statement on title will not always be checked. and in query2 Like statement on title will always be checked...
What u say ??
What I say is... trust no one on such a thing
. Not even the "pros" even though they're mostly right ;-). Instead, do a test with a million rows and find out for yourself. Many good things will come from that...
1. You'll know the truth for sure because you will have seen it with your own eyes.
2. You'll remember the correct answer longer because you will have seen it with your own eyes.
3. You'll know how to build a million row test table.
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs