š§¾ How to Insert Data into a MySQL Table ā Beginnerās Guide
After creating a table in MySQL, the next logical step is to insert data into it. Whether you’re building an application, managing user information, or working on a project, understanding how to insert records is essential.
š„ Watch the Full Tutorial
š Syntax of INSERT INTO in MySQL
INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3);
Or insert without specifying columns:
INSERT INTO table_name
VALUES (value1, value2, value3);
š” Best Practice:
Always specify column names to avoid issues with table changes.
š§Ŗ Example: Insert Into students
Table
CREATE TABLE students (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
age INT,
city VARCHAR(100)
);
INSERT INTO students (name, age, city)
VALUES ('Ravi Kumar', 21, 'Delhi');
Multiple insert:
INSERT INTO students (name, age, city)
VALUES
('Amit Sharma', 22, 'Mumbai'),
('Neha Verma', 20, 'Kolkata'),
('Sara Ali', 23, 'Chennai');
ā Result
id | name | age | city |
---|---|---|---|
1 | Ravi Kumar | 21 | Delhi |
2 | Amit Sharma | 22 | Mumbai |
3 | Neha Verma | 20 | Kolkata |
4 | Sara Ali | 23 | Chennai |
ā ļø Common Mistakes
- Incorrect column order
- Missing required fields
- Wrong data types
š Whatās Next?
Learn to:
- View data using
SELECT
- Update data with
UPDATE
- Delete data using
DELETE
š Summary
Task | SQL Syntax |
---|---|
Insert 1 row | INSERT INTO students (name, age, city) VALUES ('A', 22, 'B'); |
Insert multiple rows | INSERT INTO students (...) VALUES (...), (...); |
š Learn More with Puzzling Programmer
- š¹ Subscribe for more hands-on SQL tutorials
- š¬ Drop your queries in comments
- š§ Practice and test queries on your MySQL server