Download

Incorrect syntax near the keyword

SQL Server’s parser met a reserved word (FROM, WHERE, ORDER, KEY, IF…) where it can’t go, so none of the batch ran. The mistake is usually right before that word: a trailing comma, a missing ON or alias, a column named like a keyword, or syntax from another database.

SQL Server error 156· Tested on SQL Server 2022 RTM-CU27 (16.0.4295.3); same messages on 2019 RTM-CU32-GDR and 2025 RTM-CU9· Updated 11 October 2026

Incorrect syntax near the keyword 'FROM'.

What it means

SQL Server parses a whole batch before running any of it. Error 156 means it reached a reserved word, such as FROM, WHERE, ORDER or IF, at a point where that word can’t come next. The batch is rejected and nothing in it runs.

Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'FROM'.

The keyword in quotes is where parsing stopped, not necessarily where the mistake is. Look at what comes right before it: SELECT id, name, FROM fails at FROM because of the comma before it. When the unexpected text isn’t a reserved word, the same mistake is reported as error 102, Incorrect syntax near '…'.

Common causes

  1. A comma too many, or missing. SELECT id, name, FROM … and UPDATE … SET name = N'x', WHERE ….

  2. A reserved word used as a name. A column or table called order, key, file, plan, desc, user, group or table fails unless you put it in brackets. (status, date, name, type, value, text and level are fine.) user is a trap of its own: unbracketed in a SELECT, it doesn’t fail but returns the current database user’s name instead of the column.

  3. Syntax from MySQL or PostgreSQL that T-SQL doesn’t have:

    WrittenError on SQL ServerT-SQL
    CREATE TABLE IF NOT EXISTS t …156 near 'IF'IF OBJECT_ID(N't', N'U') IS NULL CREATE TABLE t …
    ALTER TABLE t ADD COLUMN c int156 near 'COLUMN'ALTER TABLE t ADD c int
    DELETE FROM t AS x WHERE …, UPDATE t AS x SET …156 near 'AS'DELETE x FROM t AS x WHERE …, UPDATE x SET … FROM t AS x
    INSERT … ON DUPLICATE KEY UPDATE …156 near 'ON'MERGE, or UPDATE then INSERT … WHERE NOT EXISTS
    IF x THEN … END IF156 near 'THEN'IF x BEGIN … END
    CASE … END CASE156 near 'CASE'CASE … END
    … JOIN t2 USING (id)102 near 'USING'JOIN t2 ON t2.id = t1.id
  4. A missing part of a clause. A JOIN without its ON (156 near 'WHERE'), or a subquery in FROM without an alias: SELECT * FROM (SELECT …) WHERE … fails near 'WHERE'.

  5. DROP TABLE IF EXISTS on an old server. It needs SQL Server 2016 or later; older versions reject it as a syntax error.

How to fix it

Read what comes before the keyword

Find the keyword in the line SQL Server reports (lines count from the start of the batch) and look at the token before it: a comma at the end of a list, a missing ON, a subquery that needs AS t.

Bracket names that are keywords, or rename them

CREATE TABLE dbo.order_items (id int PRIMARY KEY, [order] int NOT NULL, [key] varchar(20));
SELECT [order], [key], [user] FROM dbo.order_items;

Double quotes work as well while QUOTED_IDENTIFIER is on, as it is for most connections (sqlcmd turns it off unless you pass -I). For a new table, choose names that aren’t keywords (order_id, api_key); Microsoft’s list of reserved keywords also names words that may become reserved in future versions.

Translate the other dialect

Use the T-SQL column of the table above. For example, a derived table needs an alias, and an UPDATE through a join takes a FROM:

SELECT t.id FROM (SELECT id FROM dbo.customers) AS t WHERE t.id = 1;

UPDATE c SET name = N'Ada L.'
FROM dbo.customers AS c
WHERE c.id = 1;

Reproduce it

On SQL Server 2022 (16.0.4295.3) with sqlcmd, in a scratch schema, each statement in its own batch:

SELECT id, name, FROM seo_err_mssql.customers;
CREATE TABLE seo_err_mssql.t156 (id int, order int);
SELECT key, value FROM seo_err_mssql.customers;
SELECT c.id FROM seo_err_mssql.customers c JOIN seo_err_mssql.orders o WHERE o.customer_id = c.id;
CREATE TABLE IF NOT EXISTS seo_err_mssql.t156 (id int);
Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'FROM'.
Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'order'.
Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'key'.
Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'WHERE'.
Msg 156, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near the keyword 'IF'.
Msg 102, Level 15, State 1, Server 7732422b7f56, Line 1
Incorrect syntax near 'seo_err_mssql'.

The other rows of the table above gave the errors shown there, and IF 1 = 1 THEN SELECT 1; END IF; gave 156 twice, near 'THEN' and near 'IF'. Columns named file, plan, desc, group, table and user failed near those keywords; a table with columns status, date, type, name, value, level, text and timestamp was created without complaint. In a table with a column [user] holding ada, SELECT user, [user] returned inlet and ada. With brackets, [order], [user] and "key" all worked. SQL Server 2019 and 2025 printed the same messages.

In Inlet

The query editor highlights keywords as you type, so a column named order stands out before you run it, and its completion offers names from the live schema. Query tabs run T-SQL a batch at a time, splitting at GO. When SQL Server rejects a batch, Inlet shows its message with SQL Server error 156, state 1, severity 15 and links to this page. With your own Anthropic API key, Ask Claude (Pro, ⌘L) writes T-SQL, so it can translate a MySQL or PostgreSQL statement; it sends the schema and the SQL, never rows.

Inlet: a database client for the Mac

One native app for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and Redis. It explains errors where they happen, holds your edits until you save them, and keeps production read-only until you say so.

Version 0.1.0 · macOS 26 Tahoe or later · Apple silicon and Intel