Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Node.js MySQL Create Table

Node.js MySQL Create Table

Posted on October 19, 2025October 19, 2025 By Rishabh saini No Comments on Node.js MySQL Create Table

Node.js MySQL Create Table

The CREATE TABLE command in MySQL is used to create a new table within a database. When using Node.js to perform this operation, it’s important to specify the name of the database in your connection configuration before executing the SQL query.

Data Science Tutorial:–Click Here

Example: Creating a Table Named “employees”

Let’s start by creating a table called employees in a MySQL database using Node.js.

Create a JavaScript file named employees.js inside a folder called DBexample, and add the following code:

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

con.connect(function(err) {  
  if (err) throw err;  
  console.log("Connected!");  
  var sql = "CREATE TABLE employees (id INT, name VARCHAR(255), age INT(3), city VARCHAR(255))";  
  con.query(sql, function (err, result) {  
    if (err) throw err;  
    console.log("Table created");  
  });  
});  

Now open your command terminal and run the following command:

Introduction to Applied AI:–Click Here

node employees.js

This will create a new table named employees in the database.

Verification

To verify whether the table was created successfully, use the following MySQL command:

SHOW TABLES;

To check the structure of the created table, run:

DESC employees;

Creating a Table with a Primary Key

Download New Real Time Projects :–Click here

You can also define a primary key while creating a table. Let’s create another table named employee2 with id as the primary key.

Create a file named employee2.js in the DBexample folder and add this code:

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

con.connect(function(err) {  
  if (err) throw err;  
  console.log("Connected!");  
  var sql = "CREATE TABLE employee2 (id INT PRIMARY KEY, name VARCHAR(255), age INT(3), city VARCHAR(255))";  
  con.query(sql, function (err, result) {  
    if (err) throw err;  
    console.log("Table created");  
  });  
});  

Run the file using the command:

SQL Tutorial :–Click Here

node employee2.js

Verification

Use the following command to confirm table creation:

SHOW TABLES;

To verify that the id column is set as the primary key, use:

DESC employee2;

Adding Columns to an Existing Table

The ALTER TABLE statement allows you to modify an existing table, such as adding new columns. Let’s add a new column named salary to the employee2 table.

Complete Python Course with Advance topics:-Click Here

Replace the content of employee2.js with the following code:

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

con.connect(function(err) {  
  if (err) throw err;  
  console.log("Connected!");  
  var sql = "ALTER TABLE employee2 ADD COLUMN salary INT(10)";  
  con.query(sql, function (err, result) {  
    if (err) throw err;  
    console.log("Table altered");  
  });  
});  

Run the command:

node employee2.js

Verification

To confirm that the column has been added successfully, run:

DESC employee2;

You will see a new column named salary in the table structure.

Machine Learning Tutorial:–Click Here
Complete Advance AI topics:- CLICK HERE
Deep Learning Tutorial:– Click Here


node js mysql create table example node js mysql create table w3schools create html table in node js how to insert data dynamically in mysql using node js node js mysql query return result node js insert data into mysql node js mysql display table on html site how to create model in node js with mysql mysql create table nodejs, create table in mysql using node js, mysql create tables, javascript mysql create table, node.js sqlite3 create table, node sqlite3 create table, node js sqlite create table query, node js mysql insert table, node sqlite create table query, nodejs mysql, nodejs mysql select, create nodejs app, nodejs + mysql, mysql + nodejs, nodejs mysql query, mysql in nodejs, nodejs mysql insert, mysql and nodejs, nodejs and mysql, execute mysql nodejs, mysql with nodejs, nodejs mysql tutorial mysql create table with primary key mysql create table if not exists mysql create table data types mysql create table date mysql create table foreign key create table in mysql and insert data mysql table example how to create table in mysql command line mysql data types mysql create database mysql create table example mysql create table w3schools

    Post Views: 272
    Node.js Tutorial Tags:create nodejs app, create table in mysql using node js, execute mysql nodejs, javascript mysql create table, mysql + nodejs, mysql and nodejs, mysql create table nodejs, mysql create tables, mysql in nodejs, mysql with nodejs, node js mysql insert table, node js sqlite create table query, node sqlite create table query, node sqlite3 create table, node.js sqlite3 create table, nodejs and mysql, nodejs mysql, nodejs mysql insert, nodejs mysql query, nodejs mysql select, nodejs mysql tutorial\

    Post navigation

    Previous Post: Best Web-Based Online Voting System Using PHP & MYSQL
    Next Post: Node.js MySQL Insert Records

    More Related Articles

    Node.js V8 Engine Explained Node.js V8 Engine Explained Node.js Tutorial
    Node.js ZLIB Node.js ZLIB Node.js Tutorial
    Node.js TLS SSL Node.js TLS SSL Node.js Tutorial

    Leave a Reply Cancel reply

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

    You may also like

    1. Install Nodejs on Windows
    2. Node.js Command Line Options
    3. Node.js Assertion Testing
    4. Node.js MySQL Delete Records
    5. Node.js Create Connection with MongoDB
    6. Node.js MongoDB Filter Query

    Most Viewed Posts

    1. Top Large Language Models in 2025
    2. Online Shopping System using PHP, MySQL with Free Source Code
    3. login form in php and mysql , Step-by-Step with Free Source Code
    4. Flipkart Clone using PHP And MYSQL Free Source Code
    5. News Portal Project in PHP and MySql Free Source Code
    6. User Login & Registration System Using PHP and MySQL Free Code
    7. Top 10 Final Year Project Ideas in Python
    8. Blog Site In PHP And MYSQL With Source Code || Best Project
    9. Online Bike Rental Management System Using PHP and MySQL
    10. E learning Website in php with Free source code
    • AI
    • ASP.NET
    • Blockchain
    • ChatCPT
    • code Snippets
    • Collage Projects
    • Data Science Project
    • Data Science Tutorial
    • DBMS Tutorial
    • Deep Learning Tutorial
    • Final Year Projects
    • Free Projects
    • How to
    • html
    • Interview Question
    • Java Notes
    • Java Project
    • Java Script Notes
    • JAVASCRIPT
    • Javascript Project
    • JSP JAVA(J2EE)
    • Machine Learning Project
    • Machine Learning Tutorial
    • MySQL Tutorial
    • Node.js Tutorial
    • PHP Project
    • Portfolio
    • Python
    • Python Interview Question
    • Python Projects
    • PythonFreeProject
    • React Free Project
    • React Projects
    • Spring boot
    • SQL Tutorial
    • TOP 10
    • Uncategorized
    • Real-Time Medical Queue & Appointment System with Django
    • Online Examination System in PHP with Source Code
    • AI Chatbot for College and Hospital
    • Job Portal Web Application in PHP MySQL
    • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code

    Most Viewed Posts

    • Top Large Language Models in 2025 (8,618)
    • Online Shopping System using PHP, MySQL with Free Source Code (5,227)
    • login form in php and mysql , Step-by-Step with Free Source Code (4,879)

    Copyright © 2026 UpdateGadh.

    Powered by PressBook Green WordPress theme