0
0
SQLquery~5 mins

Why INSERT matters in SQL

Choose your learning style9 modes available
Introduction

INSERT lets you add new information into a database. Without it, you can't save new data.

When you want to add a new customer to your store's database.
When you record a new sale or transaction.
When you save a new blog post or article.
When you add a new employee's details to the company records.
When you store new user sign-up information on a website.
Syntax
SQL
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
You must specify the table name where you want to add data.
The columns and values must match in order and type.
Examples
Adds a new user named Alice who is 30 years old.
SQL
INSERT INTO users (name, age) VALUES ('Alice', 30);
Adds a new product called Book with price 9.99.
SQL
INSERT INTO products (product_name, price) VALUES ('Book', 9.99);
Adds a new order with ID 101 for customer 5 with total 150.00.
SQL
INSERT INTO orders (order_id, customer_id, total) VALUES (101, 5, 150.00);
Sample Program

This creates a table called students, adds two students, then shows all students.

SQL
CREATE TABLE students (id INT, name VARCHAR(50));
INSERT INTO students (id, name) VALUES (1, 'John');
INSERT INTO students (id, name) VALUES (2, 'Emma');
SELECT * FROM students;
OutputSuccess
Important Notes

Always check that the table exists before inserting data.

Make sure the data types of values match the column types.

Use single quotes for text values in SQL.

Summary

INSERT adds new rows to a table.

You specify the table, columns, and values.

It is essential for saving new data in databases.