Incorrect syntax near the keyword 'user'. (error 156) means SQL Server met a reserved
word where it expected a name. The most common cause is a table or column called
user, order, key or similar. Put the name in square brackets,
[user], or better, choose a name that is not a keyword.
The keyword in quotes is the exact word the parser stopped at, so search the statement for it. If it is meant as a name, bracket it everywhere it appears or rename it once.
The error
-- the error: user is a reserved keyword
CREATE TABLE user (
Id int PRIMARY KEY,
FullName nvarchar(100) NOT NULL
);
Msg 156, Level 15, State 1, Server MACHINE\LOCALDB#EAD42A01, Line 2
Incorrect syntax near the keyword 'user'.
The same message came from a column named order:
-- the error: order as a column name
CREATE TABLE dbo.Lines (
Id int PRIMARY KEY,
order int NOT NULL
);
Msg 156, Level 15, State 1, Server MACHINE\LOCALDB#EAD42A01, Line 4
Incorrect syntax near the keyword 'order'.
Why it happens
T-SQL reserves words such as USER, ORDER, SELECT and
KEY for its own grammar. When one appears where the parser expects an identifier, the
statement cannot be parsed, so nothing in that batch runs; note the Level 15 in the message, where
errors such as 213 that stop a parsed statement show Level 16. Names like these arrive naturally from a domain model, a class called
User or a property called Order, or from a schema ported from another
database. The line number points at the line inside the batch where the keyword sits, which is
why the second message says line 4.
The fix
-- fix A: brackets make the keyword an identifier
CREATE TABLE dbo.[user] (
Id int PRIMARY KEY,
FullName nvarchar(100) NOT NULL
);
INSERT INTO dbo.[user] (Id, FullName) VALUES (1, N'Maria Garcia');
SELECT Id, FullName FROM dbo.[user];
GO
-- fix B: a name that is not a keyword
CREATE TABLE dbo.Lines (
Id int PRIMARY KEY,
SortOrder int NOT NULL
);
INSERT INTO dbo.Lines (Id, SortOrder) VALUES (1, 10);
SELECT Id, SortOrder FROM dbo.Lines;
Both versions were created and returned their row. Brackets work, but every query, view and
report that touches the table must use them too, and one forgotten pair brings the error back.
Renaming to AppUser, Customers or SortOrder removes the
problem for good, which matters most for a table that many queries and an ORM will name.
Whichever you choose, be consistent across the schema. A table named [user] next to
tables named Customers and Orders invites the next developer to type the
name without brackets, and the first query they write fails with this same message. A rename done
before the table ships costs one line; a rename done later touches every query.
How it was reproduced
One script run with sqlcmd -S "(localdb)\MSSQLLocalDB" -d fix8_lab -I -i e156.sql -W on
SQL Server 2022 LocalDB 16.0.1210.3 and sqlcmd 16.0.1000.6, in a throwaway database
fix8_lab created for the test and dropped afterwards. The server's computer name in
the messages is replaced by MACHINE; nothing else changed.
Frequently asked
- What does 'Incorrect syntax near the keyword' mean in SQL Server?
- Error 156 means the parser found a reserved word, such as user or order, where it expected a name or another part of the statement. The quoted word is where parsing stopped.
- How do I use a reserved word as a table name in SQL Server?
- Put it in square brackets, for example CREATE TABLE dbo.[user], and use the brackets in every query. Renaming the table to a non-reserved word is the more durable fix.
- Why does my CREATE TABLE fail on a column named order?
- ORDER is a reserved keyword in T-SQL. Write it as [order] or rename the column, for example to SortOrder, and the statement parses.
More decoded errors in the Fixes category.