The INSERT INTO statement is used to insert a new row in a table. You can add the single record or multiple records into the table using Insert statement.
There are two different forms of Insert Statement as follows-
a. Insert Statement without Column Name
b. Insert Statement with Column Name
Insert without Column Name
Summery
The following is the simple syntax of the Insert Statement when we insert all columns values into table.
INSERT INTO table_name VALUES (val1, val2, val3, val4…)
Where table_name is the actual table name where you insert the data.
And val 1, val 2…val N are the values of the table fields
In this form you need to specify value of all columns.
Example:
Suppose you have the table tbl_Employee with the following columns:
Employee Id | EmpName | Age | Salary | Department |
SQl Query :
Insert Into tbl_Employee VALUES (8, 'Martin', 32, 'Sales', 5000.00)
after executing above sql query new row will be inserted.
Employee Id | EmpName | Age | Salary | Department |
8 | Martin | 32 | Sales | 5000.00 |
Insert With Column Name
Summery
You use the following syntax of the Insert Statement when you want to insert specified values into specified fields in a table.
INSERT INTO table_name(Col_Nam1, Col_Nam2, Col_Nam3, Col_Nam4)
VALUES (val1, val2, val3, val4…)
Where table_name is the actual table name where you insert the data.
Col_Nam1, Col_Nam2…Col_NamN are the columns names of the table.
val1, val2…valN are the values of the table fields
In this form you can Insert Value in any of the Specific column and all other column will be ‘NULL’ by default.
Example:
SQl Query:
Insert Into tbl_Employee (EmployeeId,EmpName,Age,Department,Salary) VALUES (8, 'Martin', 32, 'Sales', 5000.00)