Does specifying a foreign key make it an index?

I have table T with primary key id and foreign key f. Is f automatically indexed when it is specified as a foreign key? Do I need to explicitly add an index for f?

+3
source share
3 answers

There is no index, so yes, you need to add explicitly add the index.

Edited to add ... I probably should add that the source table / column for the data in table T must have a unique index. If you try to make FK a column that is not a unique index (either as PK or with a UNIQUE constraint), FK cannot be created.

+5
source
+5

If the foreign key is limited, the foreign key f in table T will be the primary key in the specified table T2. In SQL Server, a clustered index will be automatically created when T2 is created.

amuses

0
source

Source: https://habr.com/ru/post/1713793/


All Articles