Inserting Data in MySQL
Introduction
So far, you have created a database and a table. But right now, your table is empty.
In this lesson, you will actually start using it by adding real data.
Step 1: Check Your Table
Before inserting anything, make sure your table exists and is empty.
SELECT * FROM users;
If everything is correct, you should see an empty result.
Step 2: Insert Your First Record
Now let’s add your first user.
INSERT INTO users (name, email)
VALUES ('Rohan', 'rohan@email.com');
Run this query and then check your table again:
SELECT * FROM users;
Now you should see one row in your table.
Step 3: Understand What Happened
- A new row was added to the table
- You provided values for
nameandemail - The
idwas generated automatically
This is your first real interaction with stored data.
Step 4: Add More Data
Instead of adding one record at a time, you can insert multiple rows together.
INSERT INTO users (name, email)
VALUES
('Amit', 'amit@email.com'),
('Neha', 'neha@email.com'),
('Sara', 'sara@email.com');
Now run:
SELECT * FROM users;
You should see multiple users in your table.
Step 5: Try It Yourself
Add at least 2 more records on your own.
For example:
- Different names
- Different email addresses
This step is important. The more you type queries yourself, the faster you learn.
Things to Keep in Mind
- Text values must be inside single quotes
- The number of columns and values must match
- Order of values should match the columns
Common Mistakes
One of the most common mistakes is writing something like:
INSERT INTO users (name, email) VALUES (Rohan, rohan@email.com);
This will fail because text values are not wrapped in quotes.
Summary
In this lesson, you inserted your first data into a MySQL table.
You added single and multiple records and verified them using SELECT.
At this point, your table is no longer empty, and you are working with real data.