SQL INSERT
In this tutorial, we will discuss DML statements, as we have discussed in the previous tutorial that DML will be having four different commands like insert, update, delete, and merge.
DML: Data manipulation language statements query and manipulate data in existing schema objects. These statements do not implicitly commit the current transaction.
SQL INSERT statement is used to insert a single or multiple records in a table. The following three points are important to execute a SQL command.
- Mention the name of the table into which you want to insert.
- Mention a list of comma-separated column names within parentheses.
- Mention specify a list of comma-separated values that correspond to the column list.
INSERT: Use to Add Rows to an existing table.
Further in this tutorial, we discuss how to add the records into the table.
Syntax:
insert into users table_name (column_list)
values ( value_list);
You can see that we have created the table called users where you could see user ID username age and email as the different fields or the column names. I have executed the same below.
Example:
insert into users (user_id, user_name, age, email)
values (1, 'Ravi', 24, 'Ravi@gmail.com');
Select * from users;
Output:

There is another way where you can insert the data by inputting values rather than giving or mentioning the column names here.
Syntax:
insert into users table_name (column_list)
values ( value_list);
You need to keep in mind as user ID is a primary key, which will not allow the duplicate values; it is not allowing you to enter the duplicate values, why because the same values are going to be repeated.
So execute as the below.
Example:
insert into users values ( 2, 'sasi', 25, 'sasi@abc.com');
Select * from users;
Output:

What happens if I’m not going to mention only two columns and I wanted to insert the two columns? See, I’m going to remove this one of these two columns age and email factors. I am going to remove this and I’m going to insert only the user ID and the username. So I am going to consider this one into the fourth row and let me change this name to hari. I have executed the same below.
Syntax:
insert into table_name
values (value_list);
Example:
insert into users (user_id, user_name)
values (4, 'hari');
Select * from users;
Output:
