sql server 2000 TSQL:在表变量上创建索引

问题描述:

以下可能吗?我无法这样做.我必须有一个永久表来创建索引吗?

Is the following possible? I am unable to do so. Do I have to have a permanent table to create index?

declare @Beatles table
    (
        LastName varchar(20) ,      
        FirstName varchar(20) 
    )

CREATE CLUSTERED INDEX Index_Name_Clstd ON @Beatles(LastName)

不,您不能在表变量上创建索引 - 请参阅此 这里的文章和这个在此处发帖 将本地、全局临时表与表变量进行比较.

No, you cannot create indices on a table variable - see this article here and this posting here comparing local, global temporary tables to table variables.

限制

您不能创建非集群表变量的索引,除非索引是 PRIMARY 的副作用表上的 KEY 或 UNIQUE 约束(SQL Server 强制执行任何 UNIQUE 或PRIMARY KEY 约束使用索引).

You cannot create a non-clustered index on a table variable, unless the index is a side effect of a PRIMARY KEY or UNIQUE constraint on the table (SQL Server enforces any UNIQUE or PRIMARY KEY constraints using an index).