The INSERT INTO statement is used to add new records (rows) to a table in a database.
The INSERT INTO statement adds new data to an existing table.
INSERT INTO Students
VALUES (1, 'Rahul', 20);
This statement inserts one student record into the Students table.
The basic syntax is:
INSERT INTO table_name
VALUES (value1, value2, value3);
The order of values must match the order of columns in the table.
CREATE TABLE Students (
id INT,
name VARCHAR(100),
age INT
);
Now we can insert records into this table.
INSERT INTO Students
VALUES (1, 'Rahul', 20);
This inserts one row into the Students table.
| ID | Name | Age |
|---|---|---|
| 1 | Rahul | 20 |
Multiple records can be inserted using a single INSERT statement.
INSERT INTO Students
VALUES
(1, 'Rahul', 20),
(2, 'Priya', 21),
(3, 'Amit', 19);
This statement inserts three records.
It is generally better to specify the column names when inserting data.
INSERT INTO Students (id, name, age)
VALUES (1, 'Rahul', 20);
This makes the query easier to understand and maintain.
You can insert values into only selected columns.
INSERT INTO Students (id, name)
VALUES (2, 'Priya');
The age column is not specified in this query. Its value depends on the column definition, such as a default value or whether NULL is allowed.
Text values are normally written inside single quotes.
INSERT INTO Students (id, name, age)
VALUES (3, 'Amit', 22);
Here, Amit is a text value.
Numeric values such as integers do not normally require quotes.
INSERT INTO Students (id, name, age)
VALUES (4, 'Neha', 23);
Here, 4 and 23 are numeric values.
Date values can be inserted into a DATE column.
CREATE TABLE Students (
id INT,
name VARCHAR(100),
admission_date DATE
);
Insert a date:
INSERT INTO Students
(id, name, admission_date)
VALUES
(1, 'Rahul', '2026-09-20');
Decimal values can be inserted into columns such as DECIMAL.
CREATE TABLE Courses (
id INT,
course_name VARCHAR(100),
fee DECIMAL(10,2)
);
INSERT INTO Courses
(id, course_name, fee)
VALUES
(1, 'Python Full Stack', 15000.00);
If a column allows NULL values, you can explicitly insert NULL.
INSERT INTO Students
(id, name, age)
VALUES
(5, 'Ravi', NULL);
NULL means that the value is missing or unknown. It is not the same as zero or an empty string.
If a column uses AUTO_INCREMENT, you normally do not need to provide its value.
CREATE TABLE Students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
age INT
);
Insert a student:
INSERT INTO Students (name, age)
VALUES ('Rahul', 20);
The database can automatically generate the ID.
If a column has a default value, that value can be used when the column is omitted.
CREATE TABLE Students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
city VARCHAR(50) DEFAULT 'Aurangabad'
);
INSERT INTO Students (name)
VALUES ('Amit');
The database can use Aurangabad as the default city.
INSERT INTO Students (name, age)
VALUES
('Rahul', 20),
('Priya', 21),
('Amit', 19),
('Neha', 22);
This is a convenient way to insert several records at once.
CREATE TABLE Employees (
employee_id INT,
employee_name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10,2)
);
Insert a record:
INSERT INTO Employees
(employee_id, employee_name, department, salary)
VALUES
(1, 'Amit Kumar', 'IT', 35000.00);
CREATE TABLE Courses (
course_id INT,
course_name VARCHAR(100),
duration VARCHAR(50),
fee DECIMAL(10,2)
);
INSERT INTO Courses
(course_id, course_name, duration, fee)
VALUES
(1, 'ADCA', '6 Months', 10000.00);
INSERT INTO Courses
(course_id, course_name, duration, fee)
VALUES
(2, 'Python Full Stack', '1 Year', 35000.00),
(3, 'Tally Prime', '3 Months', 4000.00),
(4, 'Web Development', '6 Months', 15000.00);
After inserting records, you can use the SELECT statement to check the data.
SELECT * FROM Students;
The * means that all columns should be displayed.
The order of values should match the order of the specified columns.
INSERT INTO Students
(name, age, id)
VALUES
('Rahul', 20, 10);
This is valid because the values correspond to name, age, id in that order.
The number of supplied values should match the number of columns being inserted into.
Incorrect:
INSERT INTO Students (id, name, age)
VALUES (1, 'Rahul');
There are three specified columns but only two values.
Correct:
INSERT INTO Students (id, name, age)
VALUES (1, 'Rahul', 20);
Values should be compatible with the column data types.
For example:
CREATE TABLE Students (
id INT,
name VARCHAR(100)
);
A numeric ID should normally be inserted as a numeric value:
INSERT INTO Students (id, name)
VALUES (1, 'Rahul');
Text values should normally be enclosed in quotes.
Incorrect:
INSERT INTO Students (name)
VALUES (Rahul);
Correct:
INSERT INTO Students (name)
VALUES ('Rahul');
| Statement | Purpose |
|---|---|
| CREATE TABLE | Creates a new table |
| INSERT INTO | Adds records to a table |
| SELECT | Retrieves records |
CREATE TABLE Students (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
mobile VARCHAR(15),
course VARCHAR(100),
fee DECIMAL(10,2)
);
Now insert student records:
INSERT INTO Students
(name, mobile, course, fee)
VALUES
('Rahul Kumar', '9876543210', 'Python', 15000.00),
('Priya Singh', '9876543211', 'ADCA', 10000.00),
('Amit Kumar', '9876543212', 'Tally Prime', 4000.00);
SQL also supports inserting records selected from another table.
INSERT INTO NewStudents (id, name)
SELECT id, name
FROM Students;
This technique is useful when copying selected data from one table into another table.
Question: Which SQL statement is used to add a new record to an existing table?