BrokeMyLegBiking
BrokeMyLegBiking

Reputation: 5988

name of index need to be unique in database?

Do index names have to be unique accross the entire sql server database, or just for that table?

For example, should I name my index: IX_OrderLoadCarrierDelivery_OrderLoadID

for the OrderLoadID column of the OrderLoadCarrierDelivery table. Or should I just name it IX_OrderLoadID

Upvotes: 35

Views: 17430

Answers (2)

gbn
gbn

Reputation: 432261

No, per table.

That is, a unique (object_id, name) column pair in sys.indexes rather than just (name) in sys.objects (ignoring schema_id)

I'd also use something like IX_SingleColumn or IX_ParentTable. Adding table is superfluous unlike a default or check constraint, say, that is unique per DB.

Upvotes: 11

Joseph
Joseph

Reputation: 25513

They have to be unique for the table or view they were created for.

Here is a reference on Microsoft Learn that details this.

FTA:

index_name

The name of the index. Index names must be unique within a table or view, but don't have to be unique within a database. Index names must follow the rules of identifiers.

I believe the convention is:

IX_FieldName

Upvotes: 41

Related Questions