索引的名称在数据库中是唯一的吗?

时间:2020-12-05 00:25:04

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

索引名称必须在整个sql server数据库中是唯一的,还是只针对该表?

For example, should I name my index: IX_OrderLoadCarrierDelivery_OrderLoadID

例如,我应该命名我的索引:IX_OrderLoadCarrierDelivery_OrderLoadID

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

对于OrderLoadCarrierDelivery表的OrderLoadID列。或者我应该将其命名为IX_OrderLoadID

Thanks!

谢谢!

3 个解决方案

#1


19  

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

它们必须对于为其创建的表或视图是唯一的。

Here is a reference on msdn that details this.

以下是关于msdn的详细信息。

FTA:

FTA:

index_name

INDEX_NAME

Is the name of the index. Index names must be unique within a table or view but do not have to be unique within a database. Index names must follow the rules of identifiers.

是索引的名称。索引名称在表或视图中必须是唯一的,但在数据库中不必是唯一的。索引名称必须遵循标识符规则。

I believe the convention is

我相信会议是

IX_FieldName

#2


7  

No, per table.

不,每张桌子。

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

也就是说,sys.indexes中的唯一(object_id,name)列对,而不是sys.objects中的(name)(忽略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

我也使用IX_SingleColumn或IX_ParentTable之类的东西。添加表是多余的,与默认或检查约束不同,例如,每个数据库都是唯一的

#3


-4  

They have to be unique as everything gets stored in sysobjects with the name as key If you use SQL management studio, it's IX_Table_Field syntax

它们必须是唯一的,因为所有内容都存储在sysobjects中,并且名称为key如果使用SQL管理工作室,则它是IX_Table_Field语法

#1


19  

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

它们必须对于为其创建的表或视图是唯一的。

Here is a reference on msdn that details this.

以下是关于msdn的详细信息。

FTA:

FTA:

index_name

INDEX_NAME

Is the name of the index. Index names must be unique within a table or view but do not have to be unique within a database. Index names must follow the rules of identifiers.

是索引的名称。索引名称在表或视图中必须是唯一的,但在数据库中不必是唯一的。索引名称必须遵循标识符规则。

I believe the convention is

我相信会议是

IX_FieldName

#2


7  

No, per table.

不,每张桌子。

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

也就是说,sys.indexes中的唯一(object_id,name)列对,而不是sys.objects中的(name)(忽略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

我也使用IX_SingleColumn或IX_ParentTable之类的东西。添加表是多余的,与默认或检查约束不同,例如,每个数据库都是唯一的

#3


-4  

They have to be unique as everything gets stored in sysobjects with the name as key If you use SQL management studio, it's IX_Table_Field syntax

它们必须是唯一的,因为所有内容都存储在sysobjects中,并且名称为key如果使用SQL管理工作室,则它是IX_Table_Field语法