🧾 How to Insert Data into a MySQL Table – Beginner’s Guide

🧾 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

idnameagecity
1Ravi Kumar21Delhi
2Amit Sharma22Mumbai
3Neha Verma20Kolkata
4Sara Ali23Chennai

āš ļø 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

TaskSQL Syntax
Insert 1 rowINSERT INTO students (name, age, city) VALUES ('A', 22, 'B');
Insert multiple rowsINSERT 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

Leave a Reply