Incorrect syntax near the keyword ‘PRIMARY’ (Msg 156)

The error “Incorrect syntax near the keyword ‘PRIMARY’” can occur if the user tries to execute the command with a wrong syntax. Let’s consider the following example:

Assume there is a database “Adventureworks” in which new table “Table_2” was created. Two columns “Column1” and “Column2” were added to the “Table_2”, “Column1” was selected as Primary Key. Please pay attention to the following syntax:

CREATE TABLE Table_2
(Column1 INT NOT NULL,
Column2 VARCHAR(300)
CONSTRAINT Table_2_Coumnl1 PRIMARY KEY CLUSTERED (Column1))

Then a decision was made to delete the primary key, the following command was executed:

ALTER TABLE Table_2
DROP PRIMARY KEY

The next error was received:

Msg 156, Level 15, State 1, Line 20
Incorrect syntax near the keyword 'PRIMARY'.

It happened because the wrong syntax was used to delete the primary key. “DROP PRIMARY KEY” command is not suitable for SQL Server, it works with MySQL. To delete the primary key in SQL Server, use the following syntax:

ALTER TABLE Table_2
DROP CONSTRAINT Table_2_Column1