Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does creating a unique constraint on a column automatically create index?

Consider this unique constraint:

ALTER TABLE Posts ADD CONSTRAINT UQ_Posts_Name UNIQUE (Name); 

Does it automatically create index on Name column?

like image 931
Valentin V Avatar asked Aug 10 '09 12:08

Valentin V


People also ask

Are unique columns automatically indexed?

When you create a PRIMARY KEY constraint, a unique clustered index on the column or columns is automatically created if a clustered index on the table does not already exist and you do not specify a unique nonclustered index. The primary key column cannot allow NULL values.

Do I need an index if I have a unique constraint?

Conclusion. Generally there is no functional difference between a unique index and a unique constraint.

Which index is automatically created on unique key column?

A Unique index will be created automatically when you define a PRIMARY KEY or UNIQUE KEY constraints on the specified columns.

Does unique key Add index?

To answer to question in bold: Yes, making a field unique does index it like s primary key.


1 Answers

yes it does. See this

like image 66
n8wrl Avatar answered Sep 19 '22 05:09

n8wrl