我正在尝试使用准确的标签在我的一个表上创建索引。这是我正在尝试它...期望“sysname”解析为列或表名称。但是在我运行此命令并在对象资源管理器中查看它之后,它被列为
"[<Name of Missing Index, sysname + '_prod',>]".
如何以更好的描述方式定义index_names? (我试图将扩展名“_prod”添加到index_name,因为index_name的INDEX已经存在)。
USE [AMDMetrics]
GO
CREATE NONCLUSTERED INDEX
[<Name of Missing Index, sysname + '_prod',>]
ON [SMARTSOLVE].[V_CXP_CUSTOMER_PXP] ([QXP_UDF_STRING_8], [QXP_REPORT_DATE],
[QXP_XRS_DESCRIPTION])
INCLUDE ([QXP_ID], [QXP_EXCEPTION_NO], [QXP_BASE_EXCEPTION], [QXP_CATEGORY],
[QXP_OCCURENCE_DATE], [QXP_COORD_ID], [QXP_SHORT_DESC], [QXP_ROOT_CAUSE],
[QXP_DESCRIPTION], [QXP_QEI_ID], [PXP_LOT_NUMBER], [CXP_ID], [CXP_AWARE_DATE],
[QXP_XSV_CODE], [QXP_COORD_NAME], [PXP_PRODUCT_CODE], [PXP_PRODUCT_NAME],
[QXP_ORU_NAME], [QXP_RESOLUTION_DESC], [QXP_CLOSED_DATE], [CXP_CLIENT_CODE],
[CXP_CLIENT_NAME])
答案 0 :(得分:2)
我不是100%确定你要做什么,但似乎你正试图找到一种方法来正确命名你的索引(或找到一个好的命名约定)。当公约易于遵循时,公约是最好的,并且对人们有意义,而无需向他们解释。许多不同的约定适合这个MO,但最常见的是:
Index Type Prefix Complete Index name
-------------------------------------------------------------------
Index (not unique, non clustered) IDX_ IDX_<name>_<column>
Index (unique, non clustered) UDX_ UDX_<name>_<column>
Index (not unique, clustered) CIX_ CIX_<name>_<column>
Index (unique, clustered) CUX_ CUX_<name>_<column>
虽然在另一方面,我不得不质疑为什么你的INCLUDE列表中有这么多列....如果不知道这些列的大小,添加这么多列有一些缺点:
Avoid adding unnecessary columns. Adding too many index columns, key or nonkey, can have the following performance implications: - Fewer index rows will fit on a page. This could create I/O increases and reduced cache efficiency. - More disk space will be required to store the index. In particular, adding varchar(max), nvarchar(max), varbinary(max), or xml data types as nonkey index columns may significantly increase disk space requirements. This is because the column values are copied into the index leaf level. Therefore, they reside in both the index and the base table. - Index maintenance may increase the time that it takes to perform modifications, inserts, updates, or deletes, to the underlying table or indexed view. You will have to determine whether the gains in query performance outweigh the affect to performance during data modification and in additional disk space requirements.