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 helps.

Dan Guzman
SQL Server MVP

"Tom van Stiphout" <no.spam.tom7744@xxxxxxx> wrote in message news:8qqbf3190hk4cis52502s9th2ebsjjfpd5@xxxxxxxxxx
On Fri, 21 Sep 2007 19:51:14 -0000, "bobdurie@xxxxxxxxx"
<bobdurie@xxxxxxxxx> 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 helps, but i need to know for sure. Any insight would be
greatly appreciated!

Bob

.



Relevant Pages

  • Re: Cascading Changes in SQL Server
    ... is this article saying that SQL server ... >> relationship had cascading deletes and updates. ... or modify other FOREIGN KEY constraints. ...
    (microsoft.public.sqlserver.server)
  • MS SQL Server - a plethora of limitations...
    ... there are limitations in SQL Server, ... still cannot produce a decent version of MS SQL Server, ... No create or replace for functions / procs. ... > RefID1 int not null foreign key references ForKey ...
    (microsoft.public.sqlserver.programming)
  • Re: Cascading Referential Integrity Constraints
    ... That functionality won't be available until the next release of SQL Server ... I have the foreign key set to ... always delete the detail/many records when the master/one record is deleted. ...
    (microsoft.public.sqlserver.server)
  • Re: Best way to represent a many to many with optionality?
    ... DELETE Rules of the foreign key to enforce the above mentioned "business rules" without getting the "circularity/default" errors? ... SQL Server lets you specify any of the following rules to apply to either INSERT/UPDATE or DELETE: ... CustomerID bigint NOT NULL identity ... AddressTypeID tinyint NOT NULL ...
    (microsoft.public.sqlserver.programming)
  • Re: non key select or search
    ... columns in the table...that are not key columns ... INSERT statements with sample data. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)

Loading