INSERT INTO Statement in SQL

11/22/2025

INSERT INTO Statement in SQL

Go Back

INSERT INTO Statement in SQL – SQL Tutorial for Beginners

The INSERT INTO statement in SQL is used to add new records into a table. It is one of the most frequently used commands in SQL because every database application requires inserting new data.

In this beginner-friendly SQL tutorial, you will learn:

  • What INSERT INTO does

  • Syntax of INSERT INTO

  • Insert single row

  • Insert multiple rows

  • Insert data into selected columns

  • Insert using SELECT

  • Real-world examples

  • Best practices


INSERT INTO Statement in SQL

🔹 What Is INSERT INTO?

The INSERT INTO statement adds new rows to a database table.

Two main ways to use INSERT:

  1. Insert into all columns

  2. Insert into specific columns


🔸 Basic Syntax

✔ Insert into all columns (order must match the table structure)

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

✔ Insert into specific columns (recommended)

INSERT INTO table_name (column1, column2, column3)
VALUES (value1, value2, value3);

🔹 Example Table: users

idnameemailcity
1Amit[email protected]Delhi
2Neha[email protected]Mumbai

🔸 Example 1: Insert a Single Row

INSERT INTO users (name, email, city)
VALUES ('Rahul', '[email protected]', 'Bengaluru');

🔸 Example 2: Insert Into All Columns

(Useful only if you know the correct order of columns.)

INSERT INTO users
VALUES (3, 'Sara', '[email protected]', 'Pune');

🔸 Example 3: Insert Multiple Rows at Once

INSERT INTO users (name, email, city)
VALUES
('Karan', '[email protected]', 'Delhi'),
('Megha', '[email protected]', 'Hyderabad'),
('Ravi', '[email protected]', 'Kolkata');

🔸 Example 4: Insert Data with Default Values

If a column has a default value:

INSERT INTO users (name, email)
VALUES ('Shubham', '[email protected]');

The city column will use its default value.


🔸 Example 5: Insert Data Using SELECT

You can insert data from one table into another.

INSERT INTO backup_users (name, email, city)
SELECT name, email, city
FROM users
WHERE city = 'Delhi';

This copies selected users into another table.


🔸 Example 6: Insert NULL Values

INSERT INTO users (name, email, city)
VALUES ('Unknown', NULL, 'Unknown');

🔹 Real-World Use Cases

✔ User registration

INSERT INTO users (name, email, password)
VALUES ('John Doe', '[email protected]', 'hashed_pass');

✔ Add product to inventory

INSERT INTO products (product_name, price, stock)
VALUES ('Laptop', 55000, 10);

✔ Add new order

INSERT INTO orders (user_id, product, amount)
VALUES (1, 'Mobile', 20000);

🔹 Common Errors & Fixes

❗ Incorrect number of columns

INSERT INTO users VALUES ('Amit', '[email protected]');

Fix: Match number of table columns OR specify column names.

❗ Wrong data type

INSERT INTO employees (salary)
VALUES ('abc'); -- wrong

Fix: Insert valid numeric values.


🔹 Best Practices

✔ Always specify column names
✔ Use multiple-row inserts for better performance
✔ Avoid inserting hardcoded IDs when using AUTO_INCREMENT
✔ Validate data before inserting
✔ Use transactions for bulk inserts


⭐ Summary

In this SQL INSERT INTO tutorial, you learned:

  • How to insert data into tables

  • Insert single/multiple rows

  • Insert into specific columns

  • Insert using SELECT

  • Common errors and best practices

INSERT INTO is one of the most essential SQL commands for working with any database-driven application.