Node.js MySQL Drop Table

Node.js MySQL Drop Table

The DROP TABLE command in MySQL is used to permanently delete an existing table from the database. Once a table is dropped, all the data stored within it is also removed.

Data Science Tutorial:–Click Here

In this guide, we’ll learn how to drop a table named employee2 using Node.js and the MySQL module.

Step 1: Create a JavaScript File

First, create a new file named delete.js inside your DBexample folder. Then, add the following code to it:

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

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

Step 2: Run the Script

Introduction to Applied AI:–Click Here

Once you’ve saved the file, open your terminal or command prompt, navigate to the DBexample directory, and run the following command:

node delete.js

If everything is set up correctly, you’ll see the message:

Table deleted

Step 3: Verify the Deletion

Download New Real Time Projects :–Click here

Open your MySQL client or database management tool and check the list of tables in the updategadh database. You’ll notice that the employee2 table is no longer present.

SQL Tutorial :–Click Here
Deep Learning Tutorial:– Click Here
Machine Learning Tutorial:–Click Here
Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click Here


mysql drop table if exists mysql drop database mysql drop table cascade mysql drop all tables mysql drop column drop table in mysql mysql drop table with foreign key how to delete table in mysql phpmyadmin node js mysql drop table w3schools node js mysql drop table example nodejs mysql drop table, mysql drop table query nodejs, node js mysql drop table data, how to drop table in mysql node js?, drop table from database using node js mysql, postgres drop table nodejs, javascript mysql drop table data, postgres pg drop table query nodejs, javascript mysql query drop table, node.js postgresql drop table example, node.js sqlite3 drop table example, node.js sqlite3 drop table table data, nodejs mysql delete, drop table query node js, node js sqlite drop table query

Share this content:

Post Comment