Home » Node.js

Drop a MYSQL table by using Node.js

In this article, we are going to learn how to drop a MYSQL table using Node.js Server?
Submitted by Manu Jemini, on December 29, 2017


Dropping a table can cause deletion of all your data from a particular table, so always cross check the decision with a surety question.

The very first thing is to prepare a server file of node.js where we require the MySQL module to work with MySQL and after that, we prepare a connection by using mysql.createConnection() method of MySQL module.

Then attributes like a host, user, password and database name are used define inside our create connection method.

Now the last thing, all we need to create an SQL query basically a select query with an identical field to select data from MySQL table and after that we can use query() method to execute query statement with a callback in which we can throw the error if any and print the affected values.

Database details:

  • Hostname: localhost
  • Port number: 3306
  • Username: root
  • Password: 123
  • Database: demo
  • Tables name: city

Steps, we are need to follow:

  • Require MySQL module.

  • Create Connection variable using mysql.createConnection() method.
  • Connect by using con.connect() method.
  • Creating a select SQL query to select data from both the tables.
  • Execute query by using .query() method.
  • Show result.

Server file:

var mysql = require('mysql');
var con = mysql.createConnection({
  host: "",
  user: "root",
  password: "123",
  database: "demo"
con.connect(function(err) {
  if (err) throw err;
  var sql = "drop table city ";

  con.query(sql, function (err, result) {
    if (err) throw err;


Drop table in Node.js


Top MCQs

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.