🚀
1. Create Databases and Tables
++++
Data Engineering
May 2026×8 min read

Learn the first MySQL workflow: create a database, select it, create a table, insert rows, query the rows, and clean up tables or databases.

1. Create Databases and Tables

Driptanil Datta
Driptanil DattaSoftware Developer

Create Databases and Tables

A database is an organized collection of data. In MySQL, the usual beginner workflow is:

  1. Create a database.
  2. Select the database with USE.
  3. Create one or more tables.
  4. Insert rows into those tables.
  5. Query the data with SELECT.
  6. Drop temporary practice objects when you are done.

Create databases

Use CREATE DATABASE to create a new database. For practice, the script creates one database for a library and one for ecommerce.

CREATE DATABASE librarydb;
CREATE DATABASE ecommercedb;

Good naming habits matter early:

HabitWhy it helps
Use meaningful nameslibrarydb is clearer than db1.
Avoid reserved wordsNames like order or group can conflict with SQL keywords.
Stay consistent with caseMySQL table name behavior can differ across operating systems.

Select the database

Before creating a table, tell MySQL which database should receive it.

USE librarydb;

Create a table without constraints

This first table does not enforce primary keys, required fields, or relationships. That is useful for learning the table shape before adding rules.

CREATE TABLE Books (
  BookID INT,
  Title VARCHAR(25),
  Author VARCHAR(25),
  Genre VARCHAR(25),
  PublicationYear INT
);

The table columns describe one book record:

ColumnMeaning
BookIDNumeric identifier for the book.
TitleBook title.
AuthorAuthor name or short code.
GenreCategory such as romance or sci-fi.
PublicationYearYear the book was published.

Inspect and query the table

SHOW DATABASES lists available databases. SELECT * retrieves all columns from a table.

SHOW DATABASES;
 
SELECT *
FROM Books;

At this point, the table exists but has no rows.

Insert rows

Use INSERT INTO with a column list so the values are mapped clearly.

INSERT INTO Books (BookID, Title, Author, Genre, PublicationYear)
VALUES
  (1, "Twilight", "KN", "Romantic", 2020),
  (2, "Harry Potter", "ALAS", "Sci-Fi", 2018);

Then read the table again.

SELECT *
FROM Books;

Drop practice objects

DROP TABLE removes a table. DROP DATABASE removes the entire database and every table inside it.

DROP TABLE Books;
 
DROP DATABASE ecommercedb;

Use these commands carefully. In real projects, prefer backups, migrations, and review before dropping anything permanent.

Drip

Driptanil Datta

Software Developer

Building full-stack systems, one commit at a time. This blog is a centralized learning archive for developers.

Legal Notes
Disclaimer

The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP

Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

© 2026 Driptanil Datta. All rights reserved.