SQL Error: Incorrect Syntax Near the Keyword 'User'

SQL error: Incorrect syntax near the keyword 'User'

User is a reserved keyword, so you must use square brackets to make it explicit that you mean the object named "User" it, i.e. use [User] instead of User.

SQL Error: Incorrect Syntax near the keyword User

Why are you using double quotes at all? I would start with:

SELECT u.Disabled, u.UserName
FROM Database.dbo.User u
ORDER BY u.UserName ASC

You don't specify your database, but words like User are often reserved words, so they make a poor choice for an identifier name.

Incorrect syntax near the keyword 'User'. error on SQL Server

User is a reserved word and needs to be escaped, commonly by using square brackets e.g.

SELECT * FROM dbo.[User]

But double quotes also work:

SELECT * FROM dbo."User"

Although it will make your life (and any developers who follow) a lot easier if you just avoid using reserved words.

How to Solve Sql Command error invalid syntax near the keyword 'user'

user is an SQL reserved word. Change the query to:

"SELECT * FROM dbo.[user]"

It is always preferred to decorate schema / table / column names with [] to avoid these errors.

Docs:

ODBC Reserved Keywords are reserved for use in
ODBC function calls. These words do not constrain the minimum SQL
grammar; however, to ensure compatibility with drivers that support
the core SQL grammar, applications should avoid using these keywords.

c# incorrect syntax near the keyword 'user'

user is a reserve word and thus needs escaping like insert into [user] values... Or insert into "user" values...



Related Topics



Leave a reply



Submit