Solved

SQL server - Could not create index on field Inqu – this is a varchar(Max) data type

Posted on 2014-03-17
4
540 Views
Last Modified: 2014-03-19
Hi All,

I am getting below error while creating nonclustered index on table CP. Please advise how to fix below error.

Error: Could not create index on field Inqu – this is a varchar(Max) data type

Inqu column data type is varchar(max)
PO Number column datatype (varchar(50), PK)
CREATE NONCLUSTERED INDEX [_dta_index_CP_] ON [dbo].[CP]
(
                [Inqu] ASC,
                [PO Number] ASC
)
INCLUDE			([Sales Org],
                [Customer],
                [RevisionDate],
                [Status],
                [Product],
                [Comments],
                [Description],
                [Site Ids],
                [Region],
                [Ship to State],
                [Ship to City],
                [PO Date],
                [Received Date],
                [CPOA Register date],
                [Status Date],
                [Project Manager],
                [Responsible],
                [Ref 1],
                [Sales Order Numbers],
                [Network Numbers],
                [Acc Doc #],
                [Acc Doc Amount],
                [Acc Doc Date],
                [Type of PO],
                [Data Origin],
                [Created by],
                [Data Entry],
                [Modified by],
                [Date modification],
                [Company]) WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY]

Open in new window

0
Comment
Question by:sqldba2013
4 Comments
 
LVL 12

Accepted Solution

by:
Tony303 earned 100 total points
Comment Utility
Ooooh sorry,

Books Online.....

Columns that are of the large object (LOB) data types ntext, text, varchar(max), nvarchar(max), varbinary(max), xml, or image cannot be specified as key columns for an index.
0
 
LVL 5

Assisted Solution

by:dannygonzalez09
dannygonzalez09 earned 75 total points
Comment Utility
That's right.. you cannot create indexes on columns with data type - Varchar(max)...

As an alternative, if the length of the values is less than 8000 characters. you might want to  change the data type to Varchar(8000) as varchar supports a max of 8000 characters only and then create an index
0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 75 total points
Comment Utility
You're INCLUDEing most of the table, so I think it's time to step back and make sure you have the correct clustered index on the table to begin with.  If you want to pursue that, let me know.
0
 

Author Closing Comment

by:sqldba2013
Comment Utility
--
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now