Recently, I was working on a requirement that required me to retrieve data from the Order table in my SQL server database. After executing the Select query, I got the error Incorrect syntax near the keyword.
I was executing the SQL query below.
SELECT * FROM Order;
After executing the above query, I got this error, as shown in the screenshot below.
Cause of the error
I got this error since the name Order is a reserved keyword in the SQL server, and my table name is Order.
Solution
To solve this error, I had to specify the table name Order within the [ ] bracket to distinguish it from the reserved keyword. The correct, select query is below.
SELECT * FROM [Order];
After executing the above query, I got the expected output below.
You may also like to check the below-related errors
- Cannot create memory optimized tables. To create memory optimized tables, the database must have a MEMORY_OPTIMIZED_FILEGROUP that is online and has at least one container.
- Saving Changes Is Not Permitted SQL Server
Grey is a highly experienced and certified database expert with over 15 years of hands-on experience in designing, implementing, and managing complex database systems. Currently employed at WEX, USA, Grey has established a reputation as a go-to resource for all things related to database management, particularly in Microsoft SQL Server and Oracle environments. He is a Certified Microsoft SQL Server Professional (MCSE: Data Management and Analytics) and Oracle Certified Professional (OCP), with Extensive database performance tuning and optimization knowledge and a proven track record in designing and implementing high-availability database solutions.