Languages
[Edit]
EN

Node.js - MySQL Drop table

0 points
Created by:
JoanneSenior
1070

In this article, we would like to show you how to delete a table in Node.js.

const mysql = require('mysql');

const connection = mysql.createConnection({                    // gets connection with database
    host: 'localhost',  // '127.0.0.1'
    user: 'root',
    password: 'password',
    database: 'database_name',
});

connection.connect(error => {
    if (error) throw error;
    const query = 'DROP TABLE ??';
    const tableToDrop = 'users';  // DROP TABLE `users`

    connection.query(query, tableToDrop, (error, result) => {  // sends queries
        connection.end();                                      // closes connection 
        if (error) throw error;
        console.log(connection.sql);
    });
});

Database preparation

create_tables.sql file:

CREATE TABLE `users` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(100) NOT NULL,
	`role` VARCHAR(15) NOT NULL,
	PRIMARY KEY (`id`)
)
ENGINE=InnoDB;
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Node.js - MySQL

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join