{"id":1750,"date":"2011-12-03T15:42:02","date_gmt":"2011-12-03T19:42:02","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=1750"},"modified":"2011-12-13T16:10:11","modified_gmt":"2011-12-13T20:10:11","slug":"sql-primary-key-constraint-on-alter-table","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2011\/12\/sql-primary-key-constraint-on-alter-table\/","title":{"rendered":"SQL Primary Key Constraint on alter table"},"content":{"rendered":"<p>&#8211; Login to your server MS SQL Management Studio Express<\/p>\n<p>&#8211; Expand the database; expand the tables folder, right click on the table &#8220;[your table name]&#8221;, click &#8220;Open Table.&#8221; Make sure the primary key column(s) have been declared to not contain NULL values (when the table was first created). With the open table click on &#8220;Show SQL Pane&#8221; (Management Studio Express toolbar). Type the following SQL statement in the SQL pane:<\/p>\n<pre>SQL Server \/ MS Access:\r\n<code> ALTER TABLE MyTable ADD PRIMARY KEY (Id) <\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&#8211; Click on exclamation sign to execute SQL statement, or right-click in the SQL pane and select &#8220;Execute SQL.&#8221;<\/p>\n<p>If you did everything correct you will get the confirmation message that SQL command executed successful.<br \/>\n&nbsp;<\/p>\n<p>Solution for defining a primary key constraint on multiple columns, use the following SQL syntax:<\/p>\n<pre>\r\nSQL Server \/ MS Access:\r\n<code>\r\nALTER TABLE MyTable\r\nADD CONSTRAINT pk_ProductID PRIMARY KEY (Id,ItemName)\r\n<\/code>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>In case you need to drop primary key here is syntax:<\/p>\n<pre>\r\nSQL Server \/ MS Access:\r\n<code>\r\nALTER TABLE MyTable\r\nDROP CONSTRAINT id\r\n<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8211; Login to your server MS SQL Management Studio Express &#8211; Expand the database; expand the tables folder, right click on the table &#8220;[your table name]&#8221;, click &#8220;Open Table.&#8221; Make sure the primary key column(s) have been declared to not contain NULL values (when the table was first created). With the open table click on [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,32],"tags":[30,62,146],"class_list":["post-1750","post","type-post","status-publish","format-standard","hentry","category-net","category-ms-sql","tag-access-2","tag-parameters","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1750"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=1750"}],"version-history":[{"count":13,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1750\/revisions"}],"predecessor-version":[{"id":1763,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/1750\/revisions\/1763"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=1750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=1750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=1750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}