Node js Mysql Drop

MySQL DROP is used to delete table. It deletes both table structure and data. Once the data is deleted, you can not recover them. So always be careful while deleting the existing table.

To drop table using Node.js 'DROP TABLE' command is used.

Syntax

DROP Table Tablename;

Example

In this given example, we have dropped the table name 'department'.

var mysql = require("mysql");
var con = mysql.createConnection({
   host: 'localhost',
   user: 'root',
   password: 'myadmin',
   database: 'demo'
});
con.connect(function(error){
    if(error) {
        console.log('Error establishing connection to db');
        return;
    }
    console.log('connection established');
    con.query("DROP TABLE department", function(error){
        if(error){
            console.log("Error in destorying table");
            return;
        }
        console.log("TABLE dropped");
    });
});