Solved

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

Posted on 2014-03-17
4
549 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
ID: 39936220
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
ID: 39937242
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:Scott Pletcher
Scott Pletcher earned 75 total points
ID: 39937279
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
ID: 39939248
--
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

830 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