INSERT INTO Statement in SQL

11/22/2025
All Articles

INSERT INTO Statement in SQL

INSERT INTO Statement in SQL

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


πŸ”Ή 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

id name email city
1 Amit amit@example.com Delhi
2 Neha neha@example.com Mumbai

πŸ”Έ Example 1: Insert a Single Row

INSERT INTO users (name, email, city)
VALUES ('Rahul', 'rahul@example.com', 'Bengaluru');

πŸ”Έ Example 2: Insert Into All Columns

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

INSERT INTO users
VALUES (3, 'Sara', 'sara@example.com', 'Pune');

πŸ”Έ Example 3: Insert Multiple Rows at Once

INSERT INTO users (name, email, city)
VALUES
('Karan', 'karan@example.com', 'Delhi'),
('Megha', 'megha@example.com', 'Hyderabad'),
('Ravi', 'ravi@example.com', 'Kolkata');

πŸ”Έ Example 4: Insert Data with Default Values

If a column has a default value:

INSERT INTO users (name, email)
VALUES ('Shubham', 'shubham@example.com');

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', 'john@example.com', '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', 'amit@example.com');

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.

Article