Node.js MySQL Drop Table

The DROP TABLE command is used to delete or drop a table.

Let’s drop a table named employee2.

Create a js file named “delete” in DBexample folder and put the following data into it:

var mysql = require('mysql');  

var con = mysql.createConnection({  

host: "localhost",  

user: "root",  

password: "12345",  

database: ""  

});  

con.connect(function(err) {  

if (err) throw err;  

var sql = "DROP TABLE employee2";  

con.query(sql, function (err, result) {  

if (err) throw err;  

console.log("Table deleted");  

});  

});

Now open command terminal and run the following command:PlayNextMute

Current Time 0:00

/

Duration 18:10

Loaded: 2.94%

 Fullscreen

Node drop.js  
    Node.js drop table 1

    Verify that the table employee2 is no more in the database.

    Node.js drop table 2

    Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *