Skip to main content

Command Palette

Search for a command to run...

Creating a Database and Tables in MySQL with Dummy Data

Published
2 min read

I will demonstrate how to create a MySQL database and the tables that go with it using the command line in this blog article. Structured data is often managed with MySQL, a potent relational database management system. The fundamental stages will be covered in this tutorial, which include login into MySQL, making a database called denormalized_db, specifying five tables (employee, student, product, order, and sales), and populating each field with dummy data. This tutorial will provide you step-by-step instructions along with code samples, so it doesn't matter if you're a newbie or just brushing up on your abilities.

Step 1: Creating the Database denormalized_db

This command creates a new database named denormalized_db. You can name it according to your project's needs.

Step 2: Using the Database

After creating the database, you need to switch to it using the USE command.

Step 3: Defining Tables

This table holds employee details. The employee_id is the primary key, which auto-increments with each new entry.

This table holds student details. student_id serves as the primary key.

This table contains product information, with product_id as the primary key.

This table records orders, with order_id as the primary key and a foreign key reference to the producttbl.

This table tracks sales, linking to ordertbl via the order_id foreign key.

Step 4: Inserting Dummy Data into Each Table

This command inserts one sample employee record into the employeetbl.

This command inserts one sample student record.

This command inserts one product record.

This command logs one sale.

Step 5: Results!