{"id":315,"date":"2016-06-14T09:34:37","date_gmt":"2016-06-14T08:34:37","guid":{"rendered":"https:\/\/solidt.eu\/blog\/?p=315"},"modified":"2016-06-14T09:34:37","modified_gmt":"2016-06-14T08:34:37","slug":"mssql-check-if-table-or-column-exists","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/mssql-check-if-table-or-column-exists\/","title":{"rendered":"MSSQL check if Table or Column Exists"},"content":{"rendered":"<pre lang=\"sql\">\r\n\r\nIF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES \r\n    WHERE TABLE_SCHEMA = 'dbo' \r\n    AND  TABLE_NAME = 'Page'))\r\nBEGIN\r\n    PRINT 'Table exists'\t\r\nEND\r\nELSE\r\nBEGIN\r\n\tPRINT 'Table does not exists'\t\r\nEND\r\n\r\n\r\nIF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS \r\n    WHERE TABLE_SCHEMA = 'dbo' \r\n    AND  TABLE_NAME = 'Page'\r\n    AND COLUMN_NAME = 'State'))\r\nBEGIN\r\n    PRINT 'Column exists'\t\r\nEND\r\nELSE\r\nBEGIN\r\n\tPRINT 'Column does not exists'\t\r\nEND\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = &#8216;dbo&#8217; AND TABLE_NAME = &#8216;Page&#8217;)) BEGIN PRINT &#8216;Table exists&#8217; END ELSE BEGIN PRINT &#8216;Table does not exists&#8217; END IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = &#8216;dbo&#8217; AND TABLE_NAME = &#8216;Page&#8217; AND COLUMN_NAME = &#8216;State&#8217;)) BEGIN PRINT &#8216;Column exists&#8217; END ELSE BEGIN PRINT &#8216;Column does [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-other-scripts"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=315"}],"version-history":[{"count":2,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/315\/revisions\/317"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}