{"id":9720,"date":"2025-03-14T08:30:52","date_gmt":"2025-03-14T08:30:52","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=9720"},"modified":"2025-03-14T09:30:52","modified_gmt":"2025-03-14T09:30:52","slug":"upsert-data-from-csv-to-sql-server-table-via-command-line-on-windows","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/mssql-cmd\/upsert-data-from-csv-to-sql-server-table-via-command-line-on-windows.html","title":{"rendered":"Upsert data from CSV to SQL Server table via command line on Windows"},"content":{"rendered":"<p>Want to upsert data from  <a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\">CSV<\/a>  file to existing  <a href=\"https:\/\/www.microsoft.com\/en-us\/cloud-platform\/sql-server\">SQL Server<\/a>  table via command line on Windows?<\/p>\n<p>Using <a href=\"https:\/\/www.withdata.com\/mssql-cmd\/\">mssql-cmd<\/a>, a Command-Line client for SQL Server, you can upsert(merge) CSV\/TSV\/TXT data to SQL Server  table easily and fast.<\/p>\n<p>Support Windows, Linux, and MacOS.<\/p>\n<p><a href=\"#download-top\" onclick=\"dtv.style.display = 'block';\">Download mssql-cmd Windows version<\/a>  <a href=\"#download-top\" onclick=\"dtv.style.display = 'block';\"><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/download_3.jpg\" alt=\"Download mssql-cmd\" width=\"80\" height=\"22\" style=\"max-width:100%;height:auto;\" \/><\/a> <span id=\"dtv\" style=\"display: none;\"><br \/>\n<a href=\"\/down\/mssql-cmd.windows-386.zip\">mssql-cmd.windows-386.zip<\/a><br \/>\n<a href=\"\/down\/mssql-cmd.windows-amd64.zip\">mssql-cmd.windows-amd64.zip<\/a><br \/>\n<\/span><\/p>\n<p>No need to install SQL Server client library.<\/p>\n<p>Convenient to deploy to cloud. No need to run installation file, just uncompress and run, immediately.<\/p>\n<h2>Upsert\/Merge CSV\/TSV\/TXT data into SQL Server  table via command line on Windows<\/h2>\n<p>1. In interactive mode:<\/p>\n<pre>\nmssql-cmd> load loadtype=upsert\n      > updatekey=id\n      > table=media_messages \n      > datafile=f:\\media_messages.csv \n      > delimiter=, \n      > quote=\" \n      > header=y;\n<\/pre>\n<p>2. In batch mode:<\/p>\n<pre>\nmssql-cmd dsn=\"pan:withdata@192.168.0.102\/test\" task=load loadtype=upsert updatekey=id table=media_messages datafile=f:\\media_messages.csv delimiter=, quote=\" header=y quit=y\n<\/pre>\n<p>&#8220;loadtype=upsert&#8221; will update row in table if &#8220;updatekey&#8221; id exists, or insert new row.<\/p>\n<p>See <a href=\"https:\/\/www.withdata.com\/mssql-cmd\/load.html\">parameters detail<\/a>.<\/p>\n<hr style=\"clear: both;\" \/>\n<p><a href=\"https:\/\/www.withdata.com\/mssql-cmd\/\">More about mssql-cmd<\/a> &#8211; <a href=\"https:\/\/www.withdata.com\/mssql-cmd\/\">Command-Line client for SQL Server<\/a><\/p>\n<div id=\"download-bottom\" style=\"clear: both;\">\n<p>Download mssql-cmd Windows version<a href=\"#download-bottom\" onclick=\"dbv.style.display = 'block';\"><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/btn_download_green.png\" alt=\"Download mssql-cmd\" width=\"165\" height=\"50\" style=\"max-width:100%;height:auto;\" \/><\/a> <span id=\"dbv\" style=\"display: none;\"><br \/>\n<a href=\"\/down\/mssql-cmd.windows-386.zip\">mssql-cmd.windows-386.zip<\/a><br \/>\n<a href=\"\/down\/mssql-cmd.windows-amd64.zip\">mssql-cmd.windows-amd64.zip<\/a><br \/>\n<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Want to upsert data from CSV file to existing SQL Server table via command line on Windows? Using mssql-cmd, a Command-Line client for SQL Server, you can upsert(merge) CSV\/TSV\/TXT data to SQL Server table easily and fast. Support Windows, Linux, and MacOS. Download mssql-cmd Windows version mssql-cmd.windows-386.zip mssql-cmd.windows-amd64.zip No need to install SQL Server client [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2556],"tags":[73,34,1321,2474,428,2551],"class_list":["post-9720","post","type-post","status-publish","format-standard","hentry","category-mssql-cmd","tag-command-line","tag-csv","tag-sql-server","tag-sql-server-upsert-csv","tag-upsert","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9720","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=9720"}],"version-history":[{"count":4,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9720\/revisions"}],"predecessor-version":[{"id":27315,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/9720\/revisions\/27315"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=9720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=9720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=9720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}