Node.js MySQL Update
Node.js Tutorial » Node.js MySQL Update
Update command is used to manipulate records of a table.
Syntax:
column_2 = value_2, ... WHERE condition
Let us to have a table "Users" as:
ID | Name | wage | |
---|---|---|---|
1 | Clark K | clarkkent@mail.com | 1950 |
2 | John Carter | johncarter@mail.com | 2400 |
3 | Peter Parker | clarkkent@mail.com | 3125 |
MySQL Update Row
UPDATE email from the table Users where name is John Carter.
host: "localhost",
user: "your_username",
password: "your_password",
database: "my_db_name"
});
conn.connect(function(err) {
if (err) throw err;
var sql = "UPDATE users SET email = 'johncarterBoss@mail.com' WHERE name = 'John Carter'";
conn.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " row(s) updated");
});
});
Save the code above in a file named "demo_test_db_update.js", and run the file:
Which will give you this result:
After run the file your table will be:
ID | Name | wage | |
---|---|---|---|
1 | Clark K | clarkkent@mail.com | 1950 |
2 | John Carter | johncarterBoss@mail.com | 2400 |
3 | Peter Parker | clarkkent@mail.com | 3125 |
Related subjects:
node.js create database
nodejs create table
node.js MySQL select from
Order By
Tags: Node.js MySQL Update multiple rows, multiple columns, array, table, on duplicate key update, from object, update data in nodejs,
node js mysql update multiple columns
node js mysql update multiple rows
nodejs mysql update from object
update database
update data in node js
how to update data in nodejs
MySQL UPDATE all wages to 0
MySQL UPDATE all salary to 0 for wage column in table Users.
var conn = mysql.createConnection({
host: "localhost",
user: "your_username",
password: "your_password",
database: "my_db_name"
});
if (err) throw err;
var sql = "UPDATE Users SET wage = 0";
conn.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " row(s) updated");
});
});
Save the code above in a file called "demo_test_db_update2.js", and run the file:
Your database will be:
ID | Name | wage | |
---|---|---|---|
1 | Clark K | clarkkent@mail.com | 0 |
2 | John Carter | johncarterBoss@mail.com | 0 |
3 | Peter Parker | clarkkent@mail.com | 0 |
Updating Data in MySQL Database from Node.js
In this tutorial, we have shown a few details how to update data in MySQL from a node.js application.
Node.js MySQL Update multiple rows, multiple columns, array, table, on duplicate key update, from object, update data in nodejs,
node js mysql update multiple columns
node js mysql update multiple rows
nodejs mysql update from object
update database
update data in node js
how to update data in nodejs
Node.js MySQL Update - nodejs
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.