AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

Node.js MySQL Update


<< Previous Page
Nodejs tutorial
Next Page >>
Nodejs tutorial

Node.js Tutorial » Node.js MySQL Update

Update command is used to manipulate records of a table.

Syntax:

UPDATE [table_name] SET column_1 = value_1,
column_2 = value_2, ... WHERE condition

 

Let us to have a table "Users" as:

ID Name Email 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.

Example: UPDATE records
var mysql = require('mysql'); var conn = mysql.createConnection({
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:

E:\Users\Your_Name>node demo_test_db_update.js

Which will give you this result:

1 record(s) updated

After run the file your table will be:

ID Name Email wage
1 Clark K clarkkent@mail.com 1950
2 John Carter johncarterBoss@mail.com 2400
3 Peter Parker clarkkent@mail.com 3125
Note: WHERE clause specifies which row should be updated. If you omit WHERE clause, all records will be updated!

 

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.

Example:
var mysql = require('mysql');

var conn = mysql.createConnection({
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 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:

Example: : Run "demo_test_db_update2.js"
E:\Users\Your_Name>node demo_test_db_update2.js

Your database will be:

ID Name Email wage
1 Clark K clarkkent@mail.com 0
2 John Carter johncarterBoss@mail.com 0
3 Peter Parker clarkkent@mail.com 0
Note: WHERE clause it is not specified then all records it is updated!

 

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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Upload Image, display, edit and delete i...
Login Form with Image background...
How to Create an Image with Transparent ...
Portfolio Gallery Website with filtering...
Simple pagination script PHP MySQLi...
Center Image in div...
Image Hover Overlay Fade...
Sticky image / element / div on scroll...
Responsive images...
Create rounded image in HTML CSS...
Add border around image...
Position Text Over an Image HTML CSS res...
Create a Slideshow Images Gallery...
Create a Sticky Sidebar...
Search bar using CSS HTML...
Shrink Navigation Menu on Scroll...
How to Create Accordion HTML Templates...
Dropdown menu in the navigation bar...
Responsive Top Navigation Bar with mobil...
Split horizontal navigation bar...