SQL Wild Card Query – Like

Standard

When ever using SQL Wild Card Query with Like, one should always use % sign in the end and not in the beginning, as it will read all the rows of the table and will cause performance degradation issue.

For example:

if you have to find records with the Phone in between of any Table Column then you should write query like below

SELECT Name

, List Price

FROM Production.Product

WHERE Name Like “Phone%”;

This query will bring all the data rows with the Phone in the Name Column. If you write the Where clause as below then it will cause system degradation as it will read all the data rows.

WHERE Name Like “%Phone%”;

Avoid using % at the start.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s