SQL Server Storage Engine

Can you INCLUDE columns of type TEXT, NTEXT, or IMAGE?

I was sent a question today that seems like it could be something that many people get confused about – why can’t an NTEXT column be specified in the INCLUDE list of a CREATE INDEX statement in SQL 2005?

 

(In one of my internals posts from last year there’s a long explanation of included columns – its basically a way to have true covering indexes to save IOs by not having to go back to the base table once an index row has been found).

 

The answer to the question is that columns of the legacy large-value data types (TEXT, NTEXT, and IMAGE) cannot be used in the INCLUDE list. You’ll need to change the schema to use one of the new large-value data types (VARCHAR(MAX), NVARCHAR(MAX), VARBINARY(MAX), and XML).

 

The new types are stored in almost exactly the same way as the legacy types, but the internals of how they are processed by the server are different so they behave like regular data types (in that they work with most T-SQL intrinsic functions and can be used as included columns).

 

For a more detailed list of possibilities and restrictions on included columns, see the BOL topic Index with Included Columns (look for ‘included columns’ in the BOL Index).
Published Wednesday, March 14, 2007 2:31 PM by Paul Randal - MSFT
Filed under:

Comments

No Comments
Anonymous comments are disabled

About Paul Randal - MSFT

Paul started in the industry in 1994 working for DEC on the VMS file system and check/repair tools. In 1999 he moved to Microsoft to work on SQL Server, specifically on DBCC. For SQL Server 2000, he concentrated on index fragmentation (writing DBCC INDEXDEFRAG and DBCC SHOWCONTIG) plus various algorithms in DBCC CHECKDB. During SQL Server 2005 development Paul was the lead developer/manager of one the core dev teams in the Storage Engine, responsible for data access and storage (DBCC, allocation, indexes & heaps, pages/records, text/LOB storage, snapshot isolation, etc). He also spent several years rewriting DBCC CHECKDB and repair. For SQL Server 2008, Paul managed the Program Management team for the core Storage Engine to become more focused on customer/partner engagement and feature set definition. In 2007, after 8.5 years on the SQL Server team, Paul left Microsoft to join his wife, Kimberly Tripp, running SQLskills.com and pursuing his passion for presenting and consulting. Paul regularly presents at conferences and user groups around the world on high-availability, disaster recovery and Storage Engine internals. His popular blog is at http://www.sqlskills.com/blogs/paul/.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker