PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Do foreign keys generate implicit indexes?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Do foreign keys generate implicit indexes?

Réponse
 
LinkBack Outils de la discussion
Vieux 21/09/2007, 21h51   #1
bobdurie@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Do foreign keys generate implicit indexes?

If i create a simple table with a foreign key constraint, does it
create an implicit index on that given ID? I've been told this is
done in some databases, but i need to know for sure if SQL Server does
it. Has anyone heard of this before, on any other databses perhaps?

Heres an example of how the foreign key constraint is being added:

ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
[FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])

My initial testing seems to indicate adding an index on the foreign
key column s, but i need to know for sure. Any insight would be
greatly appreciated!

Bob

  Réponse avec citation
Vieux 21/09/2007, 23h37   #2
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

bobdurie@gmail.com (bobdurie@gmail.com) writes:
> If i create a simple table with a foreign key constraint, does it
> create an implicit index on that given ID?


In SQL Server, no.

> I've been told this is done in some databases, but i need to know for
> sure if SQL Server does it. Has anyone heard of this before, on any
> other databses perhaps?


I seem to recall having heard this about Sybase Anywhere.

> Heres an example of how the foreign key constraint is being added:
>
> ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
> [FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
> REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])
>
> My initial testing seems to indicate adding an index on the foreign
> key column s, but i need to know for sure. Any insight would be
> greatly appreciated!


Indeed, it is often a good idea to add indexes on foreign keys, as it
can speed up deletions considerably. And it is not uncommon to search
for data in a table on a foreign key. However, as always, you should
think twice, and not add indexes blindly. For instance, if you have a
country-code column in a address table, there is little reason to add
an index on that column, since you don't delete countries very often.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  Réponse avec citation
Vieux 22/09/2007, 01h44   #3
--CELKO--
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

>> I've been told this is done in some databases, .. <<

Yes, but better. Sybase SQL Anywhere (nee Watcom SQL) builds links
from all the FK references to the single PRIMARY KET/UNIQUE occurence
in the referenced table. Saves space, pre-joins tables for speed and
makes DRI actions both easy and fast.

SQL Server is still thinking in terms of "table = file" instead of
"table is part of a whole schema" and that "record =row" instead of
"row is made up of columns". Stonebreaker had a recent blog on column-
oriented design over contigous storage model.

  Réponse avec citation
Vieux 23/09/2007, 06h28   #4
Tom van Stiphout
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

On Fri, 21 Sep 2007 19:51:14 -0000, "bobdurie@gmail.com"
<bobdurie@gmail.com> wrote:

Microsoft Access does this, when you create a relationship between two
tables.
Check with sysindexes to see if SQL Server does this too.

-Tom.


>If i create a simple table with a foreign key constraint, does it
>create an implicit index on that given ID? I've been told this is
>done in some databases, but i need to know for sure if SQL Server does
>it. Has anyone heard of this before, on any other databses perhaps?
>
>Heres an example of how the foreign key constraint is being added:
>
>ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
>[FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
>REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])
>
>My initial testing seems to indicate adding an index on the foreign
>key column s, but i need to know for sure. Any insight would be
>greatly appreciated!
>
>Bob

  Réponse avec citation
Vieux 23/09/2007, 14h25   #5
Dan Guzman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

> Check with sysindexes to see if SQL Server does this too.

As Erland mentioned, SQL Server does not automatically index foreign key
columns. That task is left to the discretion of the DBA, who might choose
not to index the foreign column(s) due to low cardinality and static data.

--
Hope this s.

Dan Guzman
SQL Server MVP

"Tom van Stiphout" <no.spam.tom7744@cox.net> wrote in message
news:8qqbf3190hk4cis52502s9th2ebsjjfpd5@4ax.com...
> On Fri, 21 Sep 2007 19:51:14 -0000, "bobdurie@gmail.com"
> <bobdurie@gmail.com> wrote:
>
> Microsoft Access does this, when you create a relationship between two
> tables.
> Check with sysindexes to see if SQL Server does this too.
>
> -Tom.
>
>
>>If i create a simple table with a foreign key constraint, does it
>>create an implicit index on that given ID? I've been told this is
>>done in some databases, but i need to know for sure if SQL Server does
>>it. Has anyone heard of this before, on any other databses perhaps?
>>
>>Heres an example of how the foreign key constraint is being added:
>>
>>ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
>>[FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
>>REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])
>>
>>My initial testing seems to indicate adding an index on the foreign
>>key column s, but i need to know for sure. Any insight would be
>>greatly appreciated!
>>
>>Bob


  Réponse avec citation
Vieux 24/09/2007, 09h25   #6
Jack Vamvas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

Also, analyse your query requirements then apply an Indexing Strategy

--

Jack Vamvas
___________________________________
Need an IT job? http://www.ITjobfeed.com/SQL




<bobdurie@gmail.com> wrote in message
news:1190404274.471197.197240@n39g2000hsh.googlegr oups.com...
> If i create a simple table with a foreign key constraint, does it
> create an implicit index on that given ID? I've been told this is
> done in some databases, but i need to know for sure if SQL Server does
> it. Has anyone heard of this before, on any other databses perhaps?
>
> Heres an example of how the foreign key constraint is being added:
>
> ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
> [FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
> REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])
>
> My initial testing seems to indicate adding an index on the foreign
> key column s, but i need to know for sure. Any insight would be
> greatly appreciated!
>
> Bob
>



  Réponse avec citation
Vieux 24/09/2007, 15h14   #7
bobdurie@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Do foreign keys generate implicit indexes?

On Sep 24, 3:25 am, "Jack Vamvas" <DEL_TO_RE...@del.com> wrote:
> Also, analyse your query requirements then apply an Indexing Strategy
>
> --
>
> Jack Vamvas
> ___________________________________
> Need an IT job? http://www.ITjobfeed.com/SQL
>
> <bobdu...@gmail.com> wrote in message
>
> news:1190404274.471197.197240@n39g2000hsh.googlegr oups.com...
>
> > If i create a simple table with a foreign key constraint, does it
> > create an implicit index on that given ID? I've been told this is
> > done in some databases, but i need to know for sure if SQL Server does
> > it. Has anyone heard of this before, on any other databses perhaps?

>
> > Heres an example of how the foreign key constraint is being added:

>
> > ALTER TABLE [dbo].[administrators] WITH CHECK ADD CONSTRAINT
> > [FPSLUFSUOXZGAJOJ] FOREIGN KEY([AdministratorRoleID])
> > REFERENCES [dbo].[administratorroles] ([AdministratorRoleID])

>
> > My initial testing seems to indicate adding an index on the foreign
> > key column s, but i need to know for sure. Any insight would be
> > greatly appreciated!

>
> > Bob


Thanks for all the responses on this, its much appreciated!!! I also
found this article which makes me realize other people have had the
same misconceptions as me
http://www.sqlskills.com/blogs/kimbe...eyColumns.aspx

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h29.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23066 seconds with 15 queries