Home >>Nodejs Tutorial >Node.js MySQL Drop Table

Node.js MySQL Drop Table

Node.js MySQL Drop Table

The command DROP TABLE helps to delete or remove a table.

Let's drop a table called users.

In example1 folder, build a js file called "drop.js" and put the following data into it:

Example

var db = require('db');  
var con = db.createConnection({  
host: "localhost",  
user: "root",  
password: "",  
database: "phptpoint"  
});  
con.connect(function(err) {  
if (err) throw err;  
var sql = "DROP TABLE users";  
con.query(sql, function (err, result) {  
if (err) throw err;  
console.log("Table deleted");  
});  
});  

Now open terminal command and execute the following instruction:

Node drop.js

No Sidebar ads