Solved

SQL 2012 create index "incorrect syntax near 'INCLUDE'"

Posted on 2016-10-24
6
62 Views
Last Modified: 2016-10-24
A consultant created me a script to add some indexes, in it, it has a line like so

--sp_helpindex 'tmfWork_HAI'
CREATE NONCLUSTERED INDEX [IX_CreateDate_WI]
      ON [dbo].[tmfWork_HAI]
(
      CreateDate
INCLUDE
(
      WorkOrderKey
);
GO

It generates this error:  
Msg 102, Level 15, State 1, Line 9
Incorrect syntax near 'INCLUDE'.

any idea why?
0
Comment
Question by:Eric
  • 3
  • 2
6 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41857083
It's missing a close parenthesis after CreateDate:
CREATE NONCLUSTERED INDEX [IX_CreateDate_WI]
       ON [dbo].[tmfWork_HAI] (CreateDate)
 INCLUDE  (WorkOrderKey);

Open in new window

0
 
LVL 11

Author Closing Comment

by:Eric
ID: 41857274
that was it. thanks
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41857275
Fyi, your consultant left out the critical WITH clause to explicitly specify at least FILLFACTOR, and to specify the filegroup to create the index on.
1
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 11

Author Comment

by:Eric
ID: 41857288
hmm.  I have no idea the signfiicance of that. I am a infrastructure guy not SQL guy.

The script has like 30 index creations. Most are more simple than the one above and just look like:

--sp_helpindex 'tsrSR'
CREATE NONCLUSTERED INDEX [IX_ShipToAddrKey]
      ON [dbo].[tsrSR]
(
      ShipToAddrKey
);
GO

Did did a 24 hour analysis of our db performance and came back with a list of suggestions.  One of the suggestions was this list of 30 indexes.  (he also recommended removing a handful)
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41857413
He might be right on the indexes overall, but he's not really thorough and/or knowledgeable if he didn't also specify an explicit FILLFACTOR.  As a DBA, I would never accept a default FILLFACTOR.
1
 
LVL 11

Author Comment

by:Eric
ID: 41857508
thanks for the heads up
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

778 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