Solved

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

Posted on 2016-10-24
6
53 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 46

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:ScottPletcher
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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:ScottPletcher
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

895 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

16 Experts available now in Live!

Get 1:1 Help Now