I skipped the code example, and jumped to what seems to be the real question here
On top of that, a manual inspection of the index in question shows no text, ntext, image, xml or varchar(MAX), nvarchar(MAX) or varbinary(MAX). Could there be something I'm missing here?
For the record, this is a clustered index.
You certainly are missing something, and the answer is in the body of the error message:
For a clustered index, the column could be any column of the table
For Online Index Operations
there is a difference between a Clustered
and a Non-Clustered
index.
both may not contain a BLOB column in order to rebuild online,
but while a Non-Clustered Index "contains" the columns in it's definition (and included columns),
a Clustered Index "contains" the entire table with all of the columns.
in your case there is a column named MEMO
which is of data type text, ntext, image, varchar(max), nvarchar(max), varbinary(max), xml, or large CLR type.
this column is part of the table, and thus part of the Clustered index.
Your options are:
- Perform the
REBUILD
operation offline
- Upgrade to SQL Server 2012
- Change the column's data type
Guidelines for Performing Online Index Operations
Well, since you have data currently stored in SQL Server, and it's already in an NVARCHAR
column, then either it's an NVARCHAR <= 4000
(in which case you can't lose any data, and should just change all instances of NVARCHAR(8000)
to NVARCHAR(4000)
), or it's an NVARCHAR(MAX)
column, in which case you change all instances of NVARCHAR(8000)
to NVARCHAR(MAX)
. Or just leave out those CASTs
- do you really need them?
As an aside, you should probably change as NTEXT
to as NVARCHAR(MAX)
as well.
Best Answer
No, there's no magic or hand-waving here. It'd be great if synonyms, say, applied to types, but that is not the case. If you want to make these columns first-class citizens, you'll need to change the table. You can automate this to some degree, though I won't post code to help with this unless you specify what you mean exactly by "manually" and why you think this will be a significant burden you want to avoid.
To automate this, you could say:
That said, you probably don't want to use these columns with distinct / group by anyway.