I created a table in Microsoft SQL Server Management Studio and the table worked fine, no errors while building. Then i was copying the script to my project in visual studio when the following message showed:
SQL80001: Incorrect syntax ner 'OPTIMIZE_FOR_SEQUENTIAL_KEY'
I don't know why it happened, but this error was showing on this line of the code:
(PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF )
Do you guys know why the visual studio is showing that error message? How can I fix it?
when the user-generated SQL Script from the newer version of SQL Server and try to execute the same script in the older version of SQL Server, then this issue may occur. OPTIMIZE_FOR_SEQUENTIAL_KEY = { ON | OFF } applies to SQL Server (Starting with SQL Server 2019 (15.x)) and Azure SQL Database.
Finding the SQL Server version with query We can use the @@VERSION function to find out all version details of the SQL Server instance. The @@VERSION function returns a one-line string output and this output also provides all the necessary information about the SQL Server.
ALLOW_ROW_LOCKS: Determines whether row locks are allowed to access the index data. ALLOW_PAGE_LOCKS: Determines whether page locks are allowed to access the index data. MAXDOP: Used to limit the maximum number of processors used in a parallel plan execution of the index operation.
A pad index specifies index padding. When it is set to ON, then the free space percentage per the fill factor specification is applied to the intermediate-level pages of the index. When it is set to OFF, the fill factor is not specified and enough space is left for a maximum size row that an index can have. Next Page »
Make sure the target platform of your database project is SQL Server 2019 or later (including Azure SQL Database), where the OPTIMIZE_FOR_SEQUENTIAL_KEY
option was introduced. The syntax is not allowed in earlier versions.
Note this Microsoft article recommends judicious use of OPTIMIZE_FOR_SEQUENTIAL_KEY = ON
even when keys are incremental. Relevant excerpt:
If you're not experiencing the convoy phenomenon in your workload, you may not see a huge benefit from this option, and you may even see a slight degradation in performance due to the new flow control waits. You should only use this option if you have a very heavily contentious workload – one where the number of threads inserting into the index is much higher than the number of schedulers – on a clustered index with a sequential key (note that non-clustered indexes can experience this problem as well, but because they have a smaller row size they don’t have as high a tendency to form convoys so they are less likely to benefit from this option).
When you export SQL script, choose a specific version lower then 2019.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With