➕ INSERT Command in SQL

Last Updated: January 2026


The INSERT command is used to add new records (rows) into a table.

  • Adds new row(s) to a table
  • Values must match column order and data type
  • Can insert single or multiple rows

Hinglish Tip 🗣: Table me naya data dalna hoINSERT use hota hai.


🧾 Basic INSERT Syntax

INSERT INTO table_name
VALUES (value1, value2, ...);

⚠️ Column order must match table definition.

📄 Example: Insert Single Row

INSERT INTO students
VALUES (1, 'Rahul', 21);

✅ Recommended INSERT Syntax (Best Practice)

INSERT INTO students (student_id, name, age)
VALUES (2, 'Anjali', 20);

✔ Safer ✔ Order-independent ✔ Clear


➕ Insert Multiple Rows

INSERT INTO students (student_id, name, age)
VALUES
(3, 'Aman', 22),
(4, 'Neha', 19);

➕ INSERT with DEFAULT Values

INSERT INTO students (student_id, name)
VALUES (5, 'Kiran');
  • Missing columns use:
    • DEFAULT value
    • NULL (if allowed)

➕ INSERT from Another Table

INSERT INTO passed_students (student_id, name)
SELECT student_id, name
FROM students
WHERE marks >= 40;

Insert into Multiple Tables

Suppose we have two tables: table1 and table2 and there is a relationship between them as a parent and a child.

INSERT INTO table1 (column1, column2)
VALUES (value1, value2);

INSERT INTO table2 (column1, column2)
VALUES (last_insert_id(), value2);

Note: last_insert_id() returns the ID of the last inserted row in the current session.