In This Article You Will Know About SQL INSERT INTO Statement.
SQL INSERT INTO Statement– Before moving ahead, let’s know a bit about SQL ORDER BY.
Table of Contents
INSERT INTO
The INSERT INTO statement is used to insert the record in the table.
There are two possible ways to write INSERT INTO syntax:
1. Define the column’s name and values together.
Syntax –
INSERT INTO table_name (Column_name1, Column_name2, Column_name3,…)
VALUES (value1, value2, value3,……);
2. We don’t need to define a column’s name with values if we mention values for all columns but make sure that value should be mentioned in the same order as the column’s name order is defined.
INSERT INTO table_name
VALUES (value1, value2, value3,……);
Example Database
Below is the example of a database table named “details.”
Id | Name | Class | section_id |
1 | Alex | 5 | 1 |
2 | Rolex | 6 | 2 |
3 | Salex | 7 | 2 |
4 | Lelex | 8 | 3 |
5 | Kelex | 9 | 5 |
INSERT INTO Example
Example: Use INSERT INTO statement to add record in table.
INSERT INTO details (Id, Name, Class, section_id)
VALUES (6, 'Jelex', 10, 8);
As a result, it returns table after added values successfully.
Example: Use INSERT INTO statement to add record in table.
INSERT INTO details
VALUES (7, 'Gelex', 11, 6);
As a result, it returns table after added values successfully without mentioning the column’s names.
Insert data if only column is specified
Example: Insert data if columns ‘Id’, ‘Name’, and ‘section_id’ is mentioned.