{"id":4022,"date":"2024-07-18T09:48:06","date_gmt":"2024-07-18T02:48:06","guid":{"rendered":"https:\/\/www.sqlservertutorial.net\/?page_id=4022"},"modified":"2024-07-22T07:49:38","modified_gmt":"2024-07-22T00:49:38","slug":"nodejs-sql-server-bulk-insert","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/","title":{"rendered":"Node.js SQL Server Bulk Insert"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to perform a <code>BULK<\/code> <code>INSERT<\/code> command in SQL Server from a Node.js application.<\/p>\n\n\n\n<p class=\"note\">This tutorial begins where\u00a0the <a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-import-csv\/\">Import data from a CSV file into SQL Server from Node.js tutorial<\/a>\u00a0left off.<\/p>\n\n\n\n<p>We&#8217;ll perform a <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-administration\/sql-server-bulk-insert\/\">bulk insert<\/a> customer data from a CSV file into the <code>Customers<\/code> table of the <code>BookStore<\/code> database:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>csv-parse<\/code> package to read customer data from the <code>.\/data\/customers.csv<\/code> file.<\/li>\n\n\n\n<li>Use the <code>mssql<\/code> package to perform a bulk insert request.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='bulk-insert-customer-data'>Bulk insert customer data <a href=\"#bulk-insert-customer-data\" class=\"anchor\" id=\"bulk-insert-customer-data\" title=\"Anchor for Bulk insert customer data\">#<\/a><\/h2>\n\n\n\n<p>Step 1. Create a new file <code>bulk.js<\/code> in the project directory.<\/p>\n\n\n\n<p>Step 2. Copy the CSV file (customers) that contains customer data to the <code>data<\/code> directory:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">FirstName,LastName,Email,PhoneNumber,Address\nJohn,Doe,john.doe@gmail.com,123-456-7890,\"123 Elm Street, Springfield, IL\"\nJane,Smith,jane.smith@outlook.com,234-567-8901,\"456 Oak Avenue, Metropolis, NY\"\nAlice,Johnson,alice.johnson@yahoo.com,345-678-9012,\"789 Pine Road, Gotham, NJ\"<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 3. Define a function that reads customer data from the CSV file using the <code>csv-parse<\/code> package:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">const readCustomerCSV = async (filename) =&gt; {\n  const customers = &#91;];\n  return new Promise((resolve, reject) =&gt; {\n    createReadStream(filename)\n      .pipe(parse({ columns: true, trim: true }))\n      .on('data', (data) =&gt; customers.push(data))\n      .on('<span class=\"hljs-keyword\">end<\/span><span class=\"hljs-string\">', () =&gt; resolve(customers))\n      .on('<\/span><span class=\"hljs-keyword\">error<\/span><span class=\"hljs-string\">', (error) =&gt; reject(error));\n  });\n};<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>readCustomerCSV<\/code> function returns an array of customer objects, where each object contains the <code>FirstName<\/code>, <code>LastName<\/code>, <code>Email<\/code>, <code>PhoneNumber<\/code>, and <code>Address<\/code> properties.<\/p>\n\n\n\n<p>Step 4. Define the <code>insertCustomers<\/code> function that performs a bulk insert of customer data from the <code>customers.csv<\/code> file into the <code>Customers<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">const insertCustomers = async (filename) =&gt; {\n  try {\n    \/\/ read customer data from a CSV file\n    const customers = await readCustomerCSV(filename);\n\n    \/\/ Connect to the SQL Server\n    await sql.connect(config);\n\n    \/\/ Initialize a Table object\n    const table = new sql.Table('Customers');\n\n    \/\/ <span class=\"hljs-keyword\">Set<\/span> <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-literal\">false<\/span> because the <span class=\"hljs-keyword\">table<\/span> already exists.\n    \/\/ <span class=\"hljs-keyword\">If<\/span> the <span class=\"hljs-keyword\">table<\/span> does <span class=\"hljs-keyword\">not<\/span> exist, <span class=\"hljs-keyword\">set<\/span> <span class=\"hljs-keyword\">to<\/span> <span class=\"hljs-literal\">true<\/span> , it will <span class=\"hljs-keyword\">create<\/span> the <span class=\"hljs-keyword\">table<\/span>\n    table.create = <span class=\"hljs-literal\">false<\/span>;\n\n    table.columns.add('FirstName', sql.VarChar(100), { nullable: false });\n    table.columns.add('LastName', sql.VarChar(100), { nullable: false });\n    table.columns.add('Email', sql.VarChar(255), { nullable: false });\n    table.columns.add('PhoneNumber', sql.VarChar(20), { nullable: false });\n    table.columns.add('Address', sql.VarChar(255), { nullable: false });\n\n    \/\/ Add rows to the table\n    customers.forEach((c) =&gt; {\n      table.rows.add(\n        c.FirstName,\n        c.LastName,\n        c.Email,\n        c.PhoneNumber,\n        c.Address\n      );\n    });\n\n    \/\/ <span class=\"hljs-keyword\">Create<\/span> a <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">bulk<\/span> request <span class=\"hljs-keyword\">to<\/span> the Customers <span class=\"hljs-keyword\">table<\/span>\n    const request = <span class=\"hljs-keyword\">new<\/span> sql.Request();\n\n    \/\/ <span class=\"hljs-keyword\">Execute<\/span> the <span class=\"hljs-keyword\">bulk<\/span> <span class=\"hljs-keyword\">insert<\/span>\n    request.bulk(<span class=\"hljs-keyword\">table<\/span>);\n  } catch (err) {\n    console.error(err);\n  }\n};<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, read data from the CSV file by calling the <code>readCustomerCSV<\/code> function:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">const customers = await readCustomerCSV(filename);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, connect to the SQL Server:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">await sql.connect(config);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, initialize a <code>Table<\/code> object with the table name <code>Customers<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">const table = new sql.Table('Customers');<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Since the <code>Customers<\/code> table already exists, set the <code>create<\/code> property to <code>false<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">table.create = <span class=\"hljs-literal\">false<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that if the table does not exist, and you set the <code>create<\/code> property to <code>true<\/code>, it will automatically create the <code>Customers<\/code> table in SQL Server.<\/p>\n\n\n\n<p>Fourth, define the columns for the <code>Customers<\/code> table. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">table.columns.add('FirstName', sql.VarChar(100), { nullable: false });\ntable.columns.add('LastName', sql.VarChar(100), { nullable: false });\ntable.columns.add('Email', sql.VarChar(255), { nullable: false });\ntable.columns.add('PhoneNumber', sql.VarChar(20), { nullable: false });\ntable.columns.add('Address', sql.VarChar(255), { nullable: false });<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Please note that this step is required even though the <code>Customers<\/code> table already exists. Additionally, if the <code>Customers<\/code> table does not exist, you need to define the <a href=\"https:\/\/www.sqlservertutorial.net\/sql-server-basics\/sql-server-primary-key\/\">primary key column<\/a> (<code>CustomerID<\/code>) as well.<\/p>\n\n\n\n<p>Fifth, add rows to the <code>Customers<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">customers.forEach((c) =&gt; {\n  table.rows.add(c.FirstName, c.LastName, c.Email, c.PhoneNumber, c.Address);\n});<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Sixth, create a bulk request to the <code>Customers<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">const request = new sql.Request();\nrequest.bulk(table);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, display the error if it occurs in the <code>catch<\/code> block:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">console.error(err);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here&#8217;s the complete <code>bulk.js<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">import { createReadStream } from 'fs';\nimport { parse } from 'csv-parse';\nimport sql from 'mssql';\nimport { config } from '.\/config.js';\n\nconst readCustomerCSV = async (filename) =&gt; {\n  const customers = &#91;];\n  return new Promise((resolve, reject) =&gt; {\n    createReadStream(filename)\n      .pipe(parse({ columns: true, trim: true }))\n      .on('data', (data) =&gt; customers.push(data))\n      .on('<span class=\"hljs-keyword\">end<\/span><span class=\"hljs-string\">', () =&gt; resolve(customers))\n      .on('<\/span><span class=\"hljs-keyword\">error<\/span><span class=\"hljs-string\">', (error) =&gt; reject(error));\n  });\n};\n\nconst insertCustomers = async (filename) =&gt; {\n  try {\n    \/\/ read customer data from a CSV file\n    const customers = await readCustomerCSV(filename);\n\n    \/\/ Connect to the SQL Server\n    await sql.connect(config);\n\n    \/\/ Initialize a Table object\n    const table = new sql.Table('<\/span>Customers<span class=\"hljs-string\">');\n\n    \/\/ Set to false because the table already exists.\n    \/\/ If the table does not exist, set to true , it will create the table\n    table.create = false;\n\n    table.columns.add('<\/span>FirstName<span class=\"hljs-string\">', sql.VarChar(100), { nullable: false });\n    table.columns.add('<\/span>LastName<span class=\"hljs-string\">', sql.VarChar(100), { nullable: false });\n    table.columns.add('<\/span>Email<span class=\"hljs-string\">', sql.VarChar(255), { nullable: false });\n    table.columns.add('<\/span>PhoneNumber<span class=\"hljs-string\">', sql.VarChar(20), { nullable: false });\n    table.columns.add('<\/span>Address<span class=\"hljs-string\">', sql.VarChar(255), { nullable: false });\n\n    \/\/ Add rows to the table\n    \/\/ Add rows to the table\n    customers.forEach((c) =&gt; {\n      table.rows.add(\n        c.FirstName,\n        c.LastName,\n        c.Email,\n        c.PhoneNumber,\n        c.Address\n      );\n    });\n\n    \/\/ Create a new bulk request to the Customers table\n    const request = new sql.Request();\n    \/\/ Execute the bulk insert\n    request.bulk(table);\n  } catch (err) {\n    console.error(err);\n  }\n};\n\nexport { insertCustomers };<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 5. Modify the <code>index.js<\/code> file to read data from the .\/data\/<code>customer.csv<\/code> file and bulk insert it into the Customers table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">import { insertCustomers } from '.\/bulk.js';\n\ninsertCustomers('.\/data\/customers.csv');<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Step 6. Execute the following command to run the <code>bulk.js<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">npm <span class=\"hljs-keyword\">start<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='verifying-the-bulk-insert'>Verifying the bulk insert <a href=\"#verifying-the-bulk-insert\" class=\"anchor\" id=\"verifying-the-bulk-insert\" title=\"Anchor for Verifying the bulk insert\">#<\/a><\/h2>\n\n\n\n<p>Step 1. Launch SQL Server Management Studio and connect to the SQL Server.<\/p>\n\n\n\n<p>Step 2. Execute the following command to retrieve data from the <code>Customers<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> customers;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"67\" src=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png\" alt=\"node.js sql server bulk insert example\" class=\"wp-image-4024\" srcset=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png 581w, https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example-300x35.png 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='download-the-project-source-code'>Download the Project Source Code <a href=\"#download-the-project-source-code\" class=\"anchor\" id=\"download-the-project-source-code\" title=\"Anchor for Download the Project Source Code\">#<\/a><\/h2>\n\n\n\n<p><a href=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/Node.js-SQL-Server-Bulk-Insert.zip\">Download the project source code<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a Table object and call the <code>bulk()<\/code> method to perform a bulk insert request to the SQL Server.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"4022\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/\"\n\t\t\t\tdata-post-title=\"Node.js SQL Server Bulk Insert\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"4022\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/\"\n\t\t\t\tdata-post-title=\"Node.js SQL Server Bulk Insert\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Summary: in this tutorial, you will learn how to perform a BULK INSERT command in SQL Server from a Node.js application. This tutorial begins where\u00a0the Import data from a CSV file into SQL Server from Node.js tutorial\u00a0left off. We&#8217;ll perform a bulk insert customer data from a CSV file into the Customers table of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3891,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4022","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Node.js SQL Server: Bulk Insert<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js SQL Server: Bulk Insert\" \/>\n<meta property=\"og:description\" content=\"Summary: in this tutorial, you will learn how to perform a BULK INSERT command in SQL Server from a Node.js application. This tutorial begins where\u00a0the Import data from a CSV file into SQL Server from Node.js tutorial\u00a0left off. We&#8217;ll perform a bulk insert customer data from a CSV file into the Customers table of the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-22T00:49:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/\",\"name\":\"Node.js SQL Server: Bulk Insert\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/nodejs-sql-server-bulk-insert-example.png\",\"datePublished\":\"2024-07-18T02:48:06+00:00\",\"dateModified\":\"2024-07-22T00:49:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/nodejs-sql-server-bulk-insert-example.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/wp-content\\\/uploads\\\/nodejs-sql-server-bulk-insert-example.png\",\"width\":581,\"height\":67,\"caption\":\"node.js sql server bulk insert example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/nodejs-sql-server-bulk-insert\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node.js SQL Server\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js SQL Server Bulk Insert\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\",\"name\":\"SQL Server Tutorial\",\"description\":\"The Practical SQL Server Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js SQL Server: Bulk Insert","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/","og_locale":"en_US","og_type":"article","og_title":"Node.js SQL Server: Bulk Insert","og_description":"Summary: in this tutorial, you will learn how to perform a BULK INSERT command in SQL Server from a Node.js application. This tutorial begins where\u00a0the Import data from a CSV file into SQL Server from Node.js tutorial\u00a0left off. We&#8217;ll perform a bulk insert customer data from a CSV file into the Customers table of the [&hellip;]","og_url":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2024-07-22T00:49:38+00:00","og_image":[{"url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/","url":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/","name":"Node.js SQL Server: Bulk Insert","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png","datePublished":"2024-07-18T02:48:06+00:00","dateModified":"2024-07-22T00:49:38+00:00","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/#primaryimage","url":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png","contentUrl":"https:\/\/www.sqlservertutorial.net\/wp-content\/uploads\/nodejs-sql-server-bulk-insert-example.png","width":581,"height":67,"caption":"node.js sql server bulk insert example"},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"Node.js SQL Server","item":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/"},{"@type":"ListItem","position":3,"name":"Node.js SQL Server Bulk Insert"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlservertutorial.net\/#website","url":"https:\/\/www.sqlservertutorial.net\/","name":"SQL Server Tutorial","description":"The Practical SQL Server Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlservertutorial.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/comments?post=4022"}],"version-history":[{"count":5,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4022\/revisions"}],"predecessor-version":[{"id":4038,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/4022\/revisions\/4038"}],"up":[{"embeddable":true,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3891"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=4022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}