Is there a work-around for temp tables with inline indexes (containing included columns)?
ScottSS
Posts: 6 New member
We're having problems trying to check in stored procedures when they contain a temp table definition that has an inline index that has included columns. Example:
CREATE TABLE #TempExample (
EntryId INT NOT NULL,
UserId INT NULL,
Points DECIMAL(10,2) NOT NULL,
[Rank] INT NULL,
PRIMARY KEY (EntryId),
INDEX IDX_TempExample_Rank([Rank]) INCLUDE (EntryId, Points)
);
When trying to check in a procedure with something like this, the commit looks like it takes, but the stored procedure continues to show up in the list of changes.
Also, I've noticed that SQL prompt underlines "(EntryId" in the INCLUDE portion of the index definition and the mouseover text says: " Incorrect syntax near '(' " and " Incorrect syntax near 'EntryId' ".
When trying to check in a procedure with something like this, the commit looks like it takes, but the stored procedure continues to show up in the list of changes.
Also, I've noticed that SQL prompt underlines "(EntryId" in the INCLUDE portion of the index definition and the mouseover text says: " Incorrect syntax near '(' " and " Incorrect syntax near 'EntryId' ".
Tagged:
Answers
You are right that we could get around this Red Gate SQL Source Control issue by creating the indexes after the table creation. However, for performance reasons, we do not want to do this. You can see this article: https://sqlperformance.com/2017/05/sql-performance/sql-server-temporary-object-caching which states:
"A common pattern that disables caching for temporary tables is the creation of indexes after the initial table creation statement. ... In SQL Server 2014 and later, we have the option of adding non-unique nonclustered indexes directly in the table creation statement using the
INDEX
clause."Basically, this seems like valid SQL that the Red Gate SQL Prompt and SQL Source Control aren't seeing as valid.
Apologies as I don't have a SQL Server 2019 instance on hand to quickly test with, but while I get this instsalled, can I just confirm if
INDEX IDX_TempExample_Rank([Rank]) INCLUDE (EntryId, Points)
is SQL 2019 syntax?
(Trying to execute your query on SQL 2017 fails with "incorrect syntax" error)
Jessica Ramos | Product Support Engineer | Redgate Software
Have you visited our Help Center?
Here's a slightly different example:
Edit: It's actually valid SQL in version 2016 as well.
Hi @ScottSS,
Thanks for your patience with this issue SC-10856.
The development team have reviewed the bug as part of a periodical review and prioritization of open issues and, unfortunately, they are unable to fix this bug.
When reviewing bugs the development team take into account the impact it has and the number of users affected and unfortunately we are unable to fix all bugs and have to prioritize fixing the ones that cause the greatest impact.
I am going to mark this ticket as resolved, however if you have any questions regarding this please do not hesitate to reply to this message.
Thank you for your understanding!
Pete Ruiz