Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Posts
    268

    Unanswered: Foreign key constraints and indexes

    Hi All,

    I know that when you specify a PRIMARY KEY or UNIQUE constraint for a table, SQL Server creates a unique index for the primary key columns.

    What about foreign keys? Does SQL Server creates an index when you create a foreign key?
    I have looked in Books Online and on the Internet, but couldn't find any information.

    Thanks in advance.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    No indexes are created for foreign keys.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    that sure looks like an oversight, doesn't it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    I don't think Oracle does either. Does MySQL?

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yep, mysql after version umpty-ump (i'd have to look it up) -- it's one of those "silent" actions it does when it knows better than you do
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    one of my build scripts checks for and creates as need a index on every FK. This is just one of those things you learn to do.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •