Solved

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

Posted on 2016-10-24
6
42 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 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
Comment Utility
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
Comment Utility
that was it. thanks
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 11

Author Comment

by:Eric
Comment Utility
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
Comment Utility
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
Comment Utility
thanks for the heads up
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

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

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

11 Experts available now in Live!

Get 1:1 Help Now