Node.js mssql UPDATE Statements take > 1 minute to Execute

Node.js mssql update delays often stem from poor indexing, locking, or inefficient queries, requiring execution plan analysis and database optimization.

Updating records in Microsoft SQL Server from a Node.js application is a common task. Using the mssql package you can execute UPDATE queries with parameterized inputs to avoid SQL injection.

Step 1: Install mssql Package

bash
npm install mssql

Step 2: Configure MSSQL Connection

js
const sql = require('mssql');const config = { user: 'your_username', password: 'your_password', server: 'localhost', database: 'your_db', options: { encrypt: true, // Use for Azure trustServerCertificate: true, // For local dev }, };
Also Read: Impact Of Serverless On Node.js Development in 2025

Step 3: Execute an UPDATE Query

js
async function updateUserEmail(userId, newEmail) {try { let pool = await sql.connect(config); await pool .request() .input('email', sql.VarChar, newEmail) .input('id', sql.Int, userId) .query('UPDATE Users SET Email = @email WHERE Id = @id'); console.log('Update successful'); } catch (err) { console.error('Update failed', err); } }
This is type safe and SQL injection proof.

Conclusion

Now you know how to update SQL Server records from Node.js using mssql package with parameterized queries for security.
Related

How to Get the Project Root Path in Node.js When working with large Node.js projects, you often need to find the root directory at runtime…

15 Oct, 2025

If you’re trying to run nodemon from the terminal and see the error: nodemon: command not found, it usually means the nodemon package is not…

10 Oct, 2025

Writing to files is a common task in Node.js, whether for logging, saving uploads or creating reports. Node.js has various methods through the built-in fs…

07 Oct, 2025