Dark Mode
Image

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:

  1. var mysql = require('mysql');  
  2. var con = mysql.createConnection({  
  3. host: "localhost",  
  4. user: "root",  
  5. password: "12345",  
  6. database: "javatpoint"  
  7. });  
  8. con.connect(function(err) {  
  9. if (err) throw err;  
  10. var sql = "DROP TABLE employee2";  
  11. con.query(sql, function (err, result) {  
  12. if (err) throw err;  
  13. console.log("Table deleted");  
  14. });  
  15. });  

Now open command terminal and run the following command:

  1. Node drop.js  

Node.js drop table 1

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

Node.js drop table 2

Comment / Reply From