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