Node.js Tutorial

Node.js MySQL Drop Table

Node.js MySQL Drop Table

Node.js MySQL: Drop Table

The DROP TABLE command in MySQL permanently deletes a table from the database ÔÇö including all data inside it. This guide shows you how to drop a table from Node.js using the mysql package.

Node.js Tutorial:-
SQL Tutorial:-

Example: Drop the employee2 Table

// delete.js
var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "12345",
  database: "updategadh"
});

con.connect(function(err) {
  if (err) throw err;
  con.query("DROP TABLE employee2", function (err) {
    if (err) throw err;
    console.log("Table deleted");
  });
});

Run It

node delete.js
# Output: Table deleted

Safer: DROP TABLE IF EXISTS

con.query("DROP TABLE IF EXISTS employee2", function (err) {
  if (err) throw err;
  console.log("Done");
});

This avoids an error if the table is already gone.

Verify in MySQL

SHOW TABLES;
-- employee2 should no longer appear

Caution

DROP TABLE is irreversible ÔÇö there is no undo. Always back up first and double-check the table name before running it on production data.

Download New Real Time Projects:- Click here
Complete Advance AI topics:-

Conclusion

Dropping a MySQL table from Node.js is one query ÔÇö but with permanent consequences. Use IF EXISTS for idempotent scripts and always backup beforehand. For more tutorials, stay tuned to .

mysql drop table if exists
mysql drop database
mysql drop table cascade
mysql drop all tables
drop table in mysql
mysql drop table with foreign key
nodejs mysql drop table
node js mysql drop table example

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

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

Chat with us