Home > Back-end >  Incorrect syntax near 'Case'. Expecting ID, QUOTED_ID, or '.' Error in SQL Serve
Incorrect syntax near 'Case'. Expecting ID, QUOTED_ID, or '.' Error in SQL Serve

Time:10-24

I multiple tables in my database. All of my tables are showing output using select query instead of only 1 table "case". it also have data and columns but when I use it in my query it shows syntax error. I have also attached picture which have list of table and a simple query. This code is not developed by me so I am not sure why it is showing error. Is there any kind of restriction we can set so that it cannot be used in queries?

List o

CodePudding user response:

CASE is a reserved keyword in SQL Server. Therefore, you must escape it in double brackets:

SELECT * FROM dbo.[Case];

But best naming practice dictates that we should avoid naming database objects using reserved keywords. So, don't name your tables CASE.

CodePudding user response:

Reserved words are not recommended for use as a database, table, column, variable, or other object names. If you desire to use a reserved word is used as an object name in ANSI standard syntax, it must be enclosed in double-quotes OR "[]" to allow the Relational Engine (whichever that one is) that the word is being used as an object and not as a keyword in the given context. Here is the sample code.

SELECT * FROM dbo."Case"

Or

SELECT * FROM dbo.[Case]
  • Related