The INSERT INTO statement is used to add new rows (records) into a table.
Think of it as “filling data” into the structure we created with CREATE TABLE.
General Syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES
(value1, value2, value3, ...);
- table_name → The table where data will be inserted.
- column1, column2 → The specific columns you want to fill.
- value1, value2 → The actual values for those columns.
Insert into All Columns
INSERT INTO students (student_id, name, age, email, admission_date) VALUES
(1, 'Rahul Sharma', 20, 'rahul@example.com', '2025-08-29');
Insert without Specifying All Columns
If some columns have DEFAULT values (like admission_date) or are auto-incremented (SERIAL), you don’t need to provide them.
INSERT INTO students (name, age, email) VALUES
('Anjali Mehta', 19, 'anjali@example.com');
Insert Multiple Rows at Once
INSERT INTO students (name, age, email) VALUES
('Ravi Kumar', 22, 'ravi@example.com'),
('Simran Kaur', 21, 'simran@example.com'),
('Amit Patel', 20, 'amit@example.com');
Insert from Another Table
INSERT INTO alumni (id, name, graduation_year)
SELECT student_id, name, 2025
FROM students