Node JS - Node js MySQL Delete - myssql - Node - Node JS tutorial - webnode
Delete Record :
- You can delete records from an existing table by using the "DELETE " statement in mysql.

Learn Node js - node js Tutorial - node-js delete table - - node - Node js Examplesnode-js delete table
Example
- Delete any record with the address "Mountain 21":
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
con.connect(function(err) {
if (err) throw err;
var sql = "DELETE FROM customers WHERE address = 'Mountain 21'";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("Number of records deleted: " + result.affectedRows);
});
});
Notice the WHERE clause in the DELETE syntax:
- The WHERE clause specifies which record or records that should be deleted.
- If you omit the WHERE clause, all records will be deleted!
- Save the code above in a file called "wikitechy_db_delete.js" and run the Node JS Tutorial File:
Run "wikitechy_db_delete.js"
C:\Users\Your Name>node wikitechy_db_delete.js
Output:
Number of records deleted: 1