{"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

CREATE\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

<\/p>\n

Then a decision was made to delete the primary key, the following command was executed:<\/p>\n

ALTER TABLE<\/span> Table_2\r\nDROP PRIMARY KEY<\/span><\/pre>\n

The next error was received:<\/p>\n

Msg 156, Level 15, State 1, Line 20<\/span>\r\nIncorrect syntax near the keyword 'PRIMARY'.<\/span><\/pre>\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

ALTER TABLE<\/span> Table_2\r\nDROP CONSTRAINT<\/span> Table_2_Column1<\/pre>\n","protected":false},"excerpt":{"rendered":"

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":"\nIncorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy<\/title>\n<meta name=\"description\" content=\"How to solve "Incorrect syntax near the keyword 'PRIMARY' (Msg 156)"\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Incorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy\" \/>\n<meta property=\"og:description\" content=\"How to solve "Incorrect syntax near the keyword 'PRIMARY' (Msg 156)"\" \/>\n<meta property=\"og:url\" content=\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/\" \/>\n<meta property=\"og:site_name\" content=\"Sql Server Backup Academy\" \/>\n<meta property=\"article:published_time\" content=\"2015-12-16T14:48:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-17T09:11:40+00:00\" \/>\n<meta name=\"author\" content=\"Alexandr Omelchenko\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alexandr Omelchenko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/\",\"url\":\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/\",\"name\":\"Incorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy\",\"isPartOf\":{\"@id\":\"https:\/\/academy.sqlbak.com\/#website\"},\"datePublished\":\"2015-12-16T14:48:39+00:00\",\"dateModified\":\"2023-10-17T09:11:40+00:00\",\"author\":{\"@id\":\"https:\/\/academy.sqlbak.com\/#\/schema\/person\/a579cfefacf074f062823446cad811a8\"},\"description\":\"How to solve \\\"Incorrect syntax near the keyword 'PRIMARY' (Msg 156)\\\"\",\"breadcrumb\":{\"@id\":\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Incorrect syntax near the keyword ‘PRIMARY’ (Msg 156)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/academy.sqlbak.com\/#website\",\"url\":\"https:\/\/academy.sqlbak.com\/\",\"name\":\"Sql Server Backup Academy\",\"description\":\"All you need to know about Sql Server database backup\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/academy.sqlbak.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/academy.sqlbak.com\/#\/schema\/person\/a579cfefacf074f062823446cad811a8\",\"name\":\"Alexandr Omelchenko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/academy.sqlbak.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8155f02a1f0f4ef52a4a68ef379a922f?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8155f02a1f0f4ef52a4a68ef379a922f?s=96&d=monsterid&r=g\",\"caption\":\"Alexandr Omelchenko\"},\"sameAs\":[\"http:\/\/sqlbak.com\"],\"url\":\"https:\/\/academy.sqlbak.com\/author\/alexandr\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Incorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy","description":"How to solve \"Incorrect syntax near the keyword 'PRIMARY' (Msg 156)\"","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/","og_locale":"en_US","og_type":"article","og_title":"Incorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy","og_description":"How to solve \"Incorrect syntax near the keyword 'PRIMARY' (Msg 156)\"","og_url":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/","og_site_name":"Sql Server Backup Academy","article_published_time":"2015-12-16T14:48:39+00:00","article_modified_time":"2023-10-17T09:11:40+00:00","author":"Alexandr Omelchenko","twitter_card":"summary","twitter_misc":{"Written by":"Alexandr Omelchenko","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/","url":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/","name":"Incorrect syntax near the keyword 'PRIMARY' (Msg 156) - Sql Server Backup Academy","isPartOf":{"@id":"https:\/\/academy.sqlbak.com\/#website"},"datePublished":"2015-12-16T14:48:39+00:00","dateModified":"2023-10-17T09:11:40+00:00","author":{"@id":"https:\/\/academy.sqlbak.com\/#\/schema\/person\/a579cfefacf074f062823446cad811a8"},"description":"How to solve \"Incorrect syntax near the keyword 'PRIMARY' (Msg 156)\"","breadcrumb":{"@id":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/academy.sqlbak.com\/incorrect-syntax-near-the-keyword-primary-msg-156\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Incorrect syntax near the keyword ‘PRIMARY’ (Msg 156)"}]},{"@type":"WebSite","@id":"https:\/\/academy.sqlbak.com\/#website","url":"https:\/\/academy.sqlbak.com\/","name":"Sql Server Backup Academy","description":"All you need to know about Sql Server database backup","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/academy.sqlbak.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/academy.sqlbak.com\/#\/schema\/person\/a579cfefacf074f062823446cad811a8","name":"Alexandr Omelchenko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/academy.sqlbak.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8155f02a1f0f4ef52a4a68ef379a922f?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8155f02a1f0f4ef52a4a68ef379a922f?s=96&d=monsterid&r=g","caption":"Alexandr Omelchenko"},"sameAs":["http:\/\/sqlbak.com"],"url":"https:\/\/academy.sqlbak.com\/author\/alexandr\/"}]}},"_links":{"self":[{"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/posts\/3397"}],"collection":[{"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/comments?post=3397"}],"version-history":[{"count":8,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/posts\/3397\/revisions"}],"predecessor-version":[{"id":3858,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/posts\/3397\/revisions\/3858"}],"wp:attachment":[{"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/media?parent=3397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/categories?post=3397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/academy.sqlbak.com\/wp-json\/wp\/v2\/tags?post=3397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}