Node.js MySQL Update Records
Node.js MySQL Update Records
The UPDATE command in MySQL is used to modify existing records in a table. This tutorial demonstrates how to update data in a MySQL table using Node.js in a simple and professional way.
Data Science Tutorial:–Click Here
Example
Let’s say you want to update the city name in the employees table where the id is 1.
First, create a JavaScript file named update.js inside your DBexample folder and add the following code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "12345",
database: "updategadh"
});
con.connect(function(err) {
if (err) throw err;
var sql = "UPDATE employees SET city = 'Delhi' WHERE city = 'Allahabad'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log(result.affectedRows + " record(s) updated");
});
});
Introduction to Applied AI:–Click Here
Running the Code
- Open your command terminal.
- Navigate to the DBexample folder.
- Run the following command:
node update.js
Once executed, the script will update the city field from Allahabad to Delhi for the specified record in the employees table.
Download New Real Time Projects :–Click here
You can verify the update by checking your table. The record where the employee’s city was previously Allahabad will now show Delhi.
Output Example
Before Update:
| id | name | city |
|---|---|---|
| 1 | Ajeet Kumar | Allahabad |
After Update:
| id | name | city |
|---|---|---|
| 1 | Ajeet Kumar | Delhi |
SQL Tutorial :–Click Here
Deep Learning Tutorial:– Click Here
Machine Learning Tutorial:–Click Here
Complete Advance AI topics:-Â CLICK HERE
Complete Python Course with Advance topics:-Click Here
nodejs mysql update, mysql update nodejs, nodejs mysql update data, mysql update query nodejs, nodejs update mysql, update mysql nodejs, react node mysql update record, node.js mysql update, update record in react node and mysql, node js mysql update query, node js mysql update data, node.js update mysql database, node js update mysql, mysql node js update, node mysql update, update records, update in mysql node js, node.js express update record, node.js update record example, update data in node js mysql node js mysql update multiple columns update query in node js mongodb node js update query how to insert data dynamically in mysql using node js dynamic update query in node js mysql write a program to delete table records using node js and mysql database node js insert data into mysql node js mongodb update by _id node js mysql update records w3schools node js mysql update records example



Post Comment