SQL Syntax Error: Incorrect Syntax Near Keyword 'User'
In SQL, user is a reserved keyword used for system functions and objects. Therefore, when attempting to insert data into a database table using a SQL query containing the User object, it is imperative to enclose the object with square brackets to distinguish it as an object and not a keyword.
In your specific case, you encountered the error "Incorrect syntax near the keyword 'User'" when using the SQL statement INSERT INTO User (login, password, status) VALUES (@login, @password, @status) to add data to the User table. To resolve this issue, simply enclose the User object in square brackets as [User].
The updated SQL statement will look like this:
INSERT INTO [User] (login, password, status) VALUES (@login, @password, @status)
Remember, by explicitly enclosing the object name with square brackets, you are signifying to the database that User in your query refers to the object rather than the reserved keyword. This adjustment will ensure your query syntax is recognized correctly and your data insertion operation will be executed without encountering the syntax error.
The above is the detailed content of Why Does My SQL INSERT Statement Fail with 'Incorrect Syntax Near Keyword 'User' '?. For more information, please follow other related articles on the PHP Chinese website!