• Home
  • All Articles
  • SQL Interview Q & A
  • Blog Stats
  • Contact
    • Resume
    • Performance
    • Community Rules
    • Copyright
  • Tools
    • Expressor
    • Pluralsight
    • Embarcadero
    • Manage Engine
    • Idera
    • Red Gate
    • SafePeak
  • SQL Books
    • SQL Interview Q & A
    • SQL Wait Stats
    • SQL Programming
  • >>Search<<

SQL Server Journey with SQL Authority

Personal Notes of Pinal Dave

Feeds:
Posts
Comments
« SQL SERVER – Quickest Way to – Kill All Threads – Kill All User Session – Kill All Processes
SQL SERVER – Introduction to Force Index Query Hints – Index Hint – Part2 »

SQL SERVER – Introduction to Force Index Query Hints – Index Hint

February 7, 2009 by pinaldave

This article, I will start with disclaimer instead of having it at the end of article.

“SQL Server query optimizer selects the best execution plan for a query, it is recommended to use query hints by experienced developers and database administrators in case of special circumstances.”

When any query is ran SQL Server Engine determines which index has to be used. SQL Server makes uses Index which has lowest cost based on performance. Index which is the best for performance is automatically used. There are some instances when Database Developer is best judge of the index used. DBA can direct SQL Server which index to be used to execute query.

Example 1 : SQL Server using default index

USE AdventureWorks
GO
SELECT *
FROM Person.Contact
GO


Example 2: SQL Server using forced index

USE AdventureWorks
GO
SELECT ContactID
FROM Person.Contact WITH (INDEX(AK_Contact_rowguid))
GO


Example 3: SQL Server using different index for different/same tables

USE AdventureWorks
GO
SELECT c.ContactID
FROM Person.Contact c
WITH (INDEX(AK_Contact_rowguid))
INNER JOIN Person.Contact pc
WITH (INDEX(PK_Contact_ContactID))
ON c.ContactID = pc.ContactID
GO


Reference : Pinal Dave (http://blog.SQLAuthority.com)

Share this:

  • Facebook
  • Twitter
  • LinkedIn
  • StumbleUpon
  • Reddit
  • Tumblr
  • Email
  • More
  • Digg
  • Print

Like this:

Like
Be the first to like this post.

Posted in Pinal Dave, SQL, SQL Authority, SQL Constraint and Keys, SQL Index, SQL Optimization, SQL Performance, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology | Leave a Comment

  • free community tool

    Expressor
    pluralsight
    Red-Gate
    ManageEngine
    Idera
    red-gate
    SafePeak
    Koenig
  • About Pinal Dave

    Pinal Dave is a Microsoft Technology Evangelist (Database and BI). He has written over 2000 articles on the subject on his blog at http://blog.sqlauthority.com. Along with 8+ years of hands on experience he holds a Masters of Science degree and a number of certifications, including MCTS, MCDBA and MCAD (.NET). He is co-author of three SQL Server books - SQL Server Programming, SQL Wait Stats and SQL Server Interview Questions and Answers. Prior to joining Microsoft he was awarded Microsoft MVP award for three continuous years for his contribution in community.
    LinkedIn - Pinal Dave Twitter - Pinal Dave facebook
    Feed Email

    Follow @pinaldave Send +Pinal Dave an email at pinal@sqlauthority.com
  • Blog Stats

    • 36,877,581 (36 Million+)
  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 16,217 other followers

  • Next Office Hours

    Jan 3, 2012 1130 Indian Standard Time (0600 GMT)
  • Books I Authored

    . Amazon|Flipkart|Kindle

    . Amazon|Flipkart|Kindle

    Amazon|Flipkart|Kindle
  • SQLAuthority Links

    Subscribe to Newsletter
    My Homepage
    Windows Live Blog
           --------------------
    Top Downloads
       PDF Downloads
       Script Downloads

    Script Bank
       Favorite Scripts
       All Scripts - 1
       All Scripts - 2
       All Scripts - 3

    Top Articles
       Best Articles
       Favorite Articles - 1
       Favorite Articles - 2
           --------------------
    > SQL Interview Q & A <
    SQL Coding Standards
    SQL FAQ Download
           --------------------
    Jobs @ SQLAuthority
    Bookmark and Share
    AddThis Feed Button
  • About Nupur Dave

    Nupur Dave loves technology simply because it makes life more convenient. She is devoted to technology because it touches our heart makes our daily lives easier. Among the many technological programs she uses and embraces Windows Live most because she can do lots of things with ease – from photo management to movies; business emails to personal social media connections.

  • Disclaimer

    This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet/ BOL. My employer do not endorse any tools, applications, books, or concepts mentioned on the blog. I have documented my personal experience on this blog.

    • Home
    • All Articles
    • SQL Interview Q & A
    • Blog Stats
    • Contact
      • Resume
      • Performance
      • Community Rules
      • Copyright
    • Tools
      • Expressor
      • Pluralsight
      • Embarcadero
      • Manage Engine
      • Idera
      • Red Gate
      • SafePeak
    • SQL Books
      • SQL Interview Q & A
      • SQL Wait Stats
      • SQL Programming
    • >>Search<<
  • Categories

    • About Me (145)
    • Best Practices (143)
    • Business Intelligence (37)
    • CodeProject (10)
    • Data Warehousing (49)
    • Database (321)
    • DBA (137)
    • DMV (13)
    • Joes 2 Pros (47)
    • MVP (147)
    • PASS (14)
    • Readers Contribution (114)
    • Readers Question (128)
    • SharePoint (7)
    • Software Development (69)
    • SQL Add-On (99)
    • SQL Azure (15)
    • SQL Backup and Restore (79)
    • SQL BOL (11)
    • SQL Coding Standards (21)
    • SQL Constraint and Keys (57)
    • SQL Cursor (28)
    • SQL Data Storage (59)
    • SQL DateTime (47)
    • SQL DMV (23)
    • SQL Documentation (299)
    • SQL Download (311)
    • SQL Error Messages (161)
    • SQL Function (161)
    • SQL Humor (29)
    • SQL in Sixty Seconds (1)
    • SQL Index (155)
    • SQL Interview Questions and Answers (139)
    • SQL Joins (78)
    • SQL Milestone (25)
    • SQL Optimization (152)
    • SQL PASS (20)
    • SQL Performance (340)
    • SQL Puzzle (97)
    • SQL Security (127)
    • SQL Server DBCC (42)
    • SQL Server Management Studio (44)
    • SQL Service Pack (13)
    • SQL Stored Procedure (116)
    • SQL String (26)
    • SQL System Table (61)
    • SQL Trigger (24)
    • SQL User Group (57)
    • SQL Utility (153)
    • SQL View (26)
    • SQL Wait Stats (41)
    • SQL Wait Types (42)
    • SQL White Papers (67)
    • SQL XML (12)
    • SQLAuthority (632)
      • SQL Training (19)
      • SQLAuthority Author Visit (141)
      • SQLAuthority Book Review (39)
      • SQLAuthority News (577)
      • SQLAuthority Website Review (42)
    • SQLServer (229)
    • Tech (1590)
      • Pinal Dave (1577)
      • SQL Scripts (863)
    • Technology (2036)
      • PostADay (457)
      • SQL (2036)
      • SQL Authority (2036)
      • SQL Query (2035)
      • SQL Server (2036)
      • SQL Tips and Tricks (2036)
      • T SQL (2036)
    • Video (5)
  • Top 3 Commenters

      2251- Madhivanan
      474 - Imran Mohammed
      301 - Ramdas Jaya
  • Page copy protected against web site content infringement by Copyscape

Blog at WordPress.com. Fonts on this blog.

Theme: MistyLook by Sadish.


Follow

Get every new post delivered to your Inbox.

Join 16,217 other followers

Powered by WordPress.com
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.