{"id":198,"date":"2016-04-04T11:35:11","date_gmt":"2016-04-04T15:35:11","guid":{"rendered":"http:\/\/passionwind.com\/techref\/?p=198"},"modified":"2023-03-26T22:24:15","modified_gmt":"2023-03-27T02:24:15","slug":"sql-insert-if-not-exists","status":"publish","type":"post","link":"http:\/\/techref.camellarry.com\/?p=198","title":{"rendered":"SQL Insert if not exists"},"content":{"rendered":"<p>This example shows how to insert a record in an SQL table only if it does not currently exist.<\/p>\n<pre>if not exists\r\n (SELECT * FROM TEST_Table\r\n WHERE Center = '8882'\r\n AND Drive = 'K' AND Path = '\\\\DEV2\\WORKGROUP')\r\n INSERT INTO TEST_Table (Center, Drive, Path, Comment)\r\n VALUES ('8882','K','\\\\DEV2\\WORKGROUP','Stage Layout')\r\n<\/pre>\n<p>SQLite syntax:<\/p>\n<pre>INSERT OR REPLACE INTO topics (tag, topic) \r\nSELECT 'GEN:03', 'THE FALL'\r\nWHERE NOT EXISTS \r\n (SELECT * FROM topics WHERE tag = 'GEN:03' AND topic = 'THE FALL');\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This example shows how to insert a record in an SQL table only if it does not currently exist. if not exists (SELECT * FROM TEST_Table WHERE Center = &#8216;8882&#8217; AND Drive = &#8216;K&#8217; AND Path = &#8216;\\\\DEV2\\WORKGROUP&#8217;) INSERT INTO TEST_Table (Center, Drive, Path, Comment) VALUES (&#8216;8882&#8242;,&#8217;K&#8217;,&#8217;\\\\DEV2\\WORKGROUP&#8217;,&#8217;Stage Layout&#8217;) SQLite syntax: INSERT OR REPLACE INTO topics [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[29,70,74],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-sql","tag-example","tag-sql","tag-tutorial"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9t3oE-3c","_links":{"self":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=198"}],"version-history":[{"count":8,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":494,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/198\/revisions\/494"}],"wp:attachment":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}