{"id":3891,"date":"2024-07-14T19:56:26","date_gmt":"2024-07-14T12:56:26","guid":{"rendered":"https:\/\/www.sqlservertutorial.net\/?page_id=3891"},"modified":"2024-07-22T07:58:52","modified_gmt":"2024-07-22T00:58:52","slug":"nodejs-sql-server","status":"publish","type":"page","link":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/","title":{"rendered":"Node.js SQL Server"},"content":{"rendered":"\n<p>This tutorial series shows you how to interact with the SQL Server from Node.js using the <a href=\"https:\/\/www.npmjs.com\/package\/mssql\" target=\"_blank\" rel=\"noreferrer noopener\">mssql package.<\/a><\/p>\n\n\n\n<p>The <code>mssql<\/code> package has the following main features:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Multiple authentication methods<\/strong>: supports Windows and SQL Server Authentication, providing flexibility for connecting to SQL Server.<\/li>\n\n\n\n<li><strong>Connection pooling<\/strong>: efficiently manages multiple database connections, enhancing database performance and server resource utilization.<\/li>\n\n\n\n<li><strong>Parameterized queries<\/strong>: offers a secure way to execute queries with external inputs, allowing you to prevent SQL injection attacks.<\/li>\n\n\n\n<li><strong>SQL queries and stored procedures<\/strong>: allows you to execute SQL queries and stored procedures, covering a wide range of SQL Server operations.<\/li>\n\n\n\n<li><strong>Streaming<\/strong>: supports large result sets by streaming data in chunks, helping reduce memory consumption.<\/li>\n\n\n\n<li><strong>Transaction Management<\/strong>: supports transaction handling, ensuring data integrity and consistency for complex operations.<\/li>\n\n\n\n<li><strong>Detailed error handling and logging<\/strong>: provides detailed error handling and logging features, making troubleshooting easier.<\/li>\n<\/ul>\n\n\n\n<p>You should follow the tutorial in sequence for the best experience.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='getting-started'>Section 1. Getting Started <a href=\"#getting-started\" class=\"anchor\" id=\"getting-started\" title=\"Anchor for Section 1. Getting Started\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-connect\/\">Connecting to the SQL Server<\/a> &#8211; show you how to create a Node.js program that connects to the SQL Server.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='inserting-data'>Section 2. Inserting Data <a href=\"#inserting-data\" class=\"anchor\" id=\"inserting-data\" title=\"Anchor for Section 2. Inserting Data\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-insert\/\">Insert data into a table<\/a> &#8211; show you how to insert data into a table in SQL Server from Node.js<\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-import-csv\/\">Import a CSV file into a table<\/a> &#8211; learn how to read data from a CSV file and import it into a table in the SQL Server.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-bulk-insert\/\">Bulk Insert<\/a> &#8211; discover how to perform a bulk insert in SQL Server from Node.js application.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='updating-data'>Section 3. Updating Data <a href=\"#updating-data\" class=\"anchor\" id=\"updating-data\" title=\"Anchor for Section 3. Updating Data\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-update\/\">Update data from a table<\/a> &#8211; learn how to update data from a table from Node.js<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='querying-data'>Section 4. Querying Data <a href=\"#querying-data\" class=\"anchor\" id=\"querying-data\" title=\"Anchor for Section 4. Querying Data\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-select\/\">Select data from a table<\/a> &#8211; Guide you on how to select one or more rows from a table in Node.js<\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-offset-fetch\/\">Pagination<\/a> &#8211; Show you how to break up a large dataset into smaller chunks (pages) using FETCH and OFFSET clauses.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='deleting-data'>Section 5. Deleting Data <a href=\"#deleting-data\" class=\"anchor\" id=\"deleting-data\" title=\"Anchor for Section 5. Deleting Data\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-delete\/\">Delete data from a table<\/a> &#8211; Show you how to delete data from a table in SQL Server from a Node.js application.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='handling-transactions'>Section 6. Handling Transactions <a href=\"#handling-transactions\" class=\"anchor\" id=\"handling-transactions\" title=\"Anchor for Section 6. Handling Transactions\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-transaction\/\">Perform a transaction<\/a> &#8211; learn how to perform an SQL Server transaction from Node.js.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='calling-stored-procedures'>Section 7. Calling Stored Procedures <a href=\"#calling-stored-procedures\" class=\"anchor\" id=\"calling-stored-procedures\" title=\"Anchor for Section 7. Calling Stored Procedures\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-call-stored-procedures\/\">Call a stored procedure<\/a> &#8211; How to call a stored procedure from Node.js.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-calling-stored-procedures-with-output-parameters\/\">Call a stored procedure with OUTPUT parameters<\/a> &#8211; Show you how to call a stored procedure that has an OUTPUT parameter.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\" id='streaming-data'>Section 8. Streaming data <a href=\"#streaming-data\" class=\"anchor\" id=\"streaming-data\" title=\"Anchor for Section 8. Streaming data\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/nodejs-sql-server-stream\/\">Stream<\/a> &#8211; Learn how to handle a large data set efficiently using a stream.<\/li>\n<\/ul>\n<\/div><\/div>\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=\"3891\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/\"\n\t\t\t\tdata-post-title=\"Node.js SQL Server\"\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=\"3891\"\n\t\t\t\tdata-post-url=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/\"\n\t\t\t\tdata-post-title=\"Node.js SQL Server\"\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>This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":19,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3891","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<\/title>\n<meta name=\"description\" content=\"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.\" \/>\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\/\" \/>\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\" \/>\n<meta property=\"og:description\" content=\"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL Server Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-22T00:58:52+00:00\" \/>\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\\\/\",\"url\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/\",\"name\":\"Node.js SQL Server\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/#website\"},\"datePublished\":\"2024-07-14T12:56:26+00:00\",\"dateModified\":\"2024-07-22T00:58:52+00:00\",\"description\":\"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/nodejs-sql-server\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlservertutorial.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Node.js SQL Server\"}]},{\"@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","description":"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.","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\/","og_locale":"en_US","og_type":"article","og_title":"Node.js SQL Server","og_description":"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.","og_url":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/","og_site_name":"SQL Server Tutorial","article_modified_time":"2024-07-22T00:58:52+00:00","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\/","url":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/","name":"Node.js SQL Server","isPartOf":{"@id":"https:\/\/www.sqlservertutorial.net\/#website"},"datePublished":"2024-07-14T12:56:26+00:00","dateModified":"2024-07-22T00:58:52+00:00","description":"This tutorial series shows you how to interact with the SQL Server from Node.js using the mssql package.","breadcrumb":{"@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlservertutorial.net\/nodejs-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlservertutorial.net\/"},{"@type":"ListItem","position":2,"name":"Node.js SQL Server"}]},{"@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\/3891","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=3891"}],"version-history":[{"count":5,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3891\/revisions"}],"predecessor-version":[{"id":4048,"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/pages\/3891\/revisions\/4048"}],"wp:attachment":[{"href":"https:\/\/www.sqlservertutorial.net\/wp-json\/wp\/v2\/media?parent=3891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}