VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-mysql-update-statement/

⇱ Node.js MySQL Update Statement - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js MySQL Update Statement

Last Updated : 17 Feb, 2021

Node.js is an open-source platform for executing JavaScript code on the server-side. It can be downloaded from here. MySQL is an open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). It is the most popular language for adding, accessing, and managing content in a database. Here we will use the MySQL as a database for our node application. It can be downloaded from here.

Update statement: Update command is a DML command which is used for manipulating the records of a table.

Syntax:

UPDATE [table_name] SET column_A = value_A, 
 column_B = value_B, ... WHERE condition

Modules:

  • mysql: mysql module is used for interaction between the MySQL server and the node.js application.

Installing module:

npm install mysql

SQL publishers Table preview:

👁 Image

Example 1: Update all salary to 0.

Run index.js file using below command:

node index.js

Console Output: Using the Where clause is very important in UPDATE. Otherwise, the whole table may become useless.

👁 Image

Example 2: Increase the salary of publishers by 1000 who are earning more than 7000.

Run index.js file using below command:

node index.js

Console Output: Notice previous and current salary of users with id 6, 8

👁 Image
Comment

Explore