I have a table
CREATE TABLE Test
(
id int primary key,
a nvarchar(max),
c nvarchar(max),
b nvarchar(max)
)
I want to improve performance of queries to the table and want to create index (or indexes) for columns that are accessed often.
As all fields except id has type nvarchar(max) so sql-server says that I can't create index for columns where type is nvarchar(max)
Create index MyIndex on T(a)
ERROR: Column 'a' in table 'T' is of a type that is invalid for use as a key column in an index
According to the MSND it is possible to create index using followed notation
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
ON <object> ( column [ ASC | DESC ] [ ,...n ] )
[ INCLUDE ( column_name [ ,...n ] ) ]
[ ; ]
I'm interested in the option
[ INCLUDE ( column_name [ ,...n ] ) ]About it MSDN says:
INCLUDE (column [ ,... n ] ) Specifies the non-key columns to be added to the leaf level of the nonclustered index. The nonclustered index can be unique or non-unique. All data types are allowed except text, ntext, and image.
Can I create any index or alter existing PK index in order to add columns to the index?