Now let’s add some data to your table. The INSERT command adds new rows to your table.
Insert a Single Row
INSERT INTO users (username, email) VALUES ('alice', 'alice@example.com');
What this does:
INSERT INTO users= tells MySQL to add data to theuserstable(username, email)= specifies which fields we’re providing values forVALUES ('alice', 'alice@example.com')= the actual data to insert
Important: The order of values must match the order of fields. In this example, the first value (‘alice’) goes into the first field (username), and the second value (‘alice@example.com’) goes into the second field (email).
Note: We don’t include the id field because it has AUTO_INCREMENT - MySQL will automatically assign the next available number (1, 2, 3, etc.).
Insert Multiple Rows
You can add multiple users at once:
INSERT INTO users (username, email) VALUES
('bob', 'bob@example.com'),
('charlie', 'charlie@example.com'),
('diana', 'diana@example.com');
Check Your Data
After inserting data, run SELECT * FROM users; again to see your table now has data:
| id | username | |
|---|---|---|
| 1 | alice | alice@example.com |
| 2 | bob | bob@example.com |
| 3 | charlie | charlie@example.com |
| 4 | diana | diana@example.com |
View Specific Fields
You can also select only certain fields:
SELECT username, email FROM users;
This will show only the username and email columns, not the id.