{"id":3397,"date":"2015-12-16T09:48:39","date_gmt":"2015-12-16T14:48:39","guid":{"rendered":"https:\/\/academy.sqlbak.com\/?p=3397"},"modified":"2023-10-17T05:11:40","modified_gmt":"2023-10-17T09:11:40","slug":"incorrect-syntax-near-the-keyword-primary-msg-156","status":"publish","type":"post","link":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/","title":{"rendered":"Incorrect syntax near the keyword ‘PRIMARY’ (Msg 156)"},"content":{"rendered":"
The error “Incorrect syntax near the keyword ‘PRIMARY’<\/em>” can occur\u00a0if the user tries to execute the command with a\u00a0wrong\u00a0syntax. Let’s consider the following example:<\/p>\n 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:<\/p>\n <\/p>\n Then a decision was made to delete the primary key, the following command was executed:<\/p>\n The next error was received:<\/p>\n It happened because the wrong syntax was used to delete the primary key. “DROP PRIMARY KEY<\/span>” command is not suitable for SQL Server, it works with MySQL. To delete the primary key in SQL Server, use the following syntax:<\/p>\n The error “Incorrect syntax near the keyword ‘PRIMARY’” can occur\u00a0if the user tries to execute the command with a\u00a0wrong\u00a0syntax. 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 […]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[159],"tags":[],"yoast_head":"\nCREATE\u00a0TABLE<\/span> Table_2\r\n(<\/span>Column1 INT<\/span> NOT\u00a0NULL<\/span>,\r\nColumn2 VARCHAR<\/span>(<\/span>300)<\/span>\r\nCONSTRAINT<\/span>\u00a0Table_2_Coumnl1 PRIMARY\u00a0KEY\u00a0CLUSTERED<\/span> (<\/span>Column1))<\/span><\/pre>\n
ALTER TABLE<\/span> Table_2\r\nDROP PRIMARY KEY<\/span><\/pre>\n
Msg 156, Level 15, State 1, Line 20<\/span>\r\nIncorrect syntax near the keyword 'PRIMARY'.<\/span><\/pre>\n
ALTER TABLE<\/span> Table_2\r\nDROP CONSTRAINT<\/span> Table_2_Column1<\/pre>\n","protected":false},"excerpt":{"rendered":"