{"id":2582,"date":"2013-08-01T14:04:55","date_gmt":"2013-08-01T14:04:55","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=2582"},"modified":"2024-08-17T05:47:09","modified_gmt":"2024-08-17T05:47:09","slug":"replace-update-or-insert-a-row-into-sqlite-table","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/sqlite\/replace-update-or-insert-a-row-into-sqlite-table.html","title":{"rendered":"Replace Update or Insert a row Into Sqlite Table"},"content":{"rendered":"<p>In Mysql, if you want to either updates or inserts a row in a table, depending if the table already has a row that matches the data, you can use &#8220;ON DUPLICATE KEY UPDATE&#8221;.<\/p>\n<p>How to do it in Sqlite?<\/p>\n<p>Use &#8220;INSERT OR REPLACE INTO&#8221; .<\/p>\n<p>For example:<\/p>\n<pre>INSERT OR REPLACE INTO Employee (id, name, role) \r\nVALUES (1, 'John Foo', 'CEO');<\/pre>\n<p>You can see this page for more information: <a href=\"http:\/\/stackoverflow.com\/questions\/418898\/sqlite-upsert-not-insert-or-replace\">http:\/\/stackoverflow.com\/questions\/418898\/sqlite-upsert-not-insert-or-replace<\/a><\/p>\n<p>See also:<\/p>\n<p><a href=\"http:\/\/www.withdata.com\/blog\/txttosqlite\/upsert-data-from-csv-file-to-sqlite-without-programming.html\"> Upsert data from CSV to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/txttosqlite\/upsert-data-from-tsv-file-to-sqlite-without-programming.html\"> Upsert data from TSV to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/txttosqlite\/upsert-data-from-txt-file-to-sqlite-without-programming.html\"> Upsert data from TXT to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/xlstosqlite\/upsert-data-from-excel-file-to-sqlite-without-programming.html\"> Upsert data from Excel to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/xmltosqlite\/upsert-data-from-xml-file-to-sqlite-without-programming.html\"> Upsert data from XML to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/jsontosqlite\/upsert-data-from-json-file-to-sqlite-without-programming.html\"> Upsert data from JSON to SQLite<\/a><br \/>\n<a href=\"http:\/\/www.withdata.com\/blog\/sqltosqlite\/upsert-data-from-sql-file-to-sqlite-without-programming.html\"> Upsert data from SQL file to SQLite<\/a><\/p>\n<p>Replace (Update\/Insert) a row into other DB:<\/p>\n<p>In SQL Server,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html\">https:\/\/www.withdata.com\/blog\/sql-server\/replace-update-or-insert-a-row-into-sql-server-table.html<\/a><\/p>\n<p>In Oracle,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html\">https:\/\/www.withdata.com\/blog\/oracle\/replace-update-or-insert-a-row-into-oracle-table-merge-into.html<\/a><\/p>\n<p>In DB2,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html\">https:\/\/www.withdata.com\/blog\/db2\/replace-update-or-insert-a-row-into-db2-table-merge-into.html<\/a><\/p>\n<p>In PostgreSQL,\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/postgresql\/replace-update-or-insert-a-row-into-postgresql-table.html\">https:\/\/www.withdata.com\/blog\/postgresql\/replace-update-or-insert-a-row-into-postgresql-table.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Mysql, if you want to either updates or inserts a row in a table, depending if the table already has a row that matches the data, you can use &#8220;ON DUPLICATE KEY UPDATE&#8221;. How to do it in Sqlite? Use &#8220;INSERT OR REPLACE INTO&#8221; . For example: INSERT OR REPLACE INTO Employee (id, name, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[429],"tags":[238,239,1369,428],"class_list":["post-2582","post","type-post","status-publish","format-standard","hentry","category-sqlite","tag-merge-into","tag-replace-into","tag-sqlite","tag-upsert"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=2582"}],"version-history":[{"count":9,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2582\/revisions"}],"predecessor-version":[{"id":21735,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2582\/revisions\/21735"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=2582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=2582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=2582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}