Node.js MySQL Drop Table

Node.js MySQL Drop 

MySQL package is used to Drop table from database

DROP TABLE mysql statement is used to drop table in mysql database.

Example : 

const mysql = require('mysql');

const db = mysql.createConnection({

     host: "localhost",
     user: "root",
     password: "*******",
     database : "aryadb"

  });

// connect to database

db.connect((err) => {

    if (err) {

        throw err;

    }else{

     console.log('Connected to database!');

     db.query("drop table employee ", function (err, result) {
          if (err) throw err;
               console.log("employee table is deleted!");
          }); 
    }

});

Write above code in server.js file and run this program as below.

D:\nodejs\website> node server.js  

It gives output as below.

employee table is deleted!

Comments

Leave a Reply

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

13857