D365FO: "Incorrect syntax near '('" error during the package deployment
Recently we faced an X++ DB sync issue with the following exception log.
Database execution failed: Incorrect syntax near '('.
ALTER TABLE DBO.FEETABLE ADD CONSTRAINT I_29109FEEIDX PRIMARY KEY CLUSTERED(PARTITION,DATAAREAID,INVENTSITEREFERENCE,INVENTSITEID,FROMDATE) INCLUDE (TODATE)?WITH (MAXDOP = 2, DATA_COMPRESSION = ROW) ; | SQL Exception Number – 102
It looked quite strange, and not clear what was actually wrong.
After some research, we have found that an index with the Included column was created on the table, and then this index was made as a primary(probably during the best practice correction)
But the problem is that primary indexes are not allowing included columns in SQL Server.
The solution was simple to remove the included column from the index.
Microsoft should probably detect this during the compile phase, as you may get a failed deployment due to this.
I hope this helps someone in case you see the same error.