SQL Server 2000: Indexing Table Variables
Question: Is index creation possible on SQL Server 2000 table variables?
The answer is nuanced. In SQL Server 2000, indexes on table variables are implicitly created, meaning you can't explicitly define them. Instead, you achieve indexing through unique or primary key constraints.
Implicit Indexing Advantages:
Important Considerations:
Illustrative Syntax:
<code class="language-sql">DECLARE @TEMPTABLE TABLE ( [ID] [INT] NOT NULL PRIMARY KEY, [Name] [NVARCHAR] (255) COLLATE DATABASE_DEFAULT NULL, UNIQUE NONCLUSTERED ([Name], [ID]) );</code>
This example demonstrates creating a table variable with a primary key index on the ID
column and a unique, non-clustered index on the Name
column. Note that this is achieved through constraint definitions, not explicit CREATE INDEX
statements.
The above is the detailed content of Can Indexes Be Created on SQL Server 2000 Table Variables?. For more information, please follow other related articles on the PHP Chinese website!