Quick Reach
Insert into table values
The insert into sql statement is used to insert data into tables of SQL databases. You can insert data by specifying column names or without column names in SQL insert into – values statement.
Syntax of Insert into values sql statement
The general syntax of SQL insert into statement with values:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
Insert into table_name (
Col1,
Col2,
Col3,
Col4
…..
…..
Colx)
Values (
Col1_value,
Col2_value,
Col3_value,
Col4_value,
…..
…..
Colx_value )
);
|
Where insert into statement is followed by name of table where you are intended to insert data. After table name, fields or column names of table in parenthesis.
Lastly values of those columns or fields in same sequence as column names are.
This is one way of using insert into statement. The other way of using insert statement is without column names:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
Insert into table_name Values (
Col1_value,
Col2_value,
Col3_value,
Col4_value,
…..
…..
Colx_value )
);
|
That is, you can only provide insert into with values without giving column names.
Example of insert into – values statement with column names
We have a table tbl_employee with five columns (emp_id, emp_name, emp_age, emp_salary and joining_date). Now let us insert rows into tbl_employee by using insert into statements and specifying column names.
Insert into values with column names example
See graphic of this example
1
2
3
|
insert into tbl_employee (emp_id, emp_name, emp_age, emp_salary, joining_date)
Values (004, Shan, 22, 1500, ‘2009/01/01’)
|
Example of insert into statement without column names
In examples below we will insert a row without specifying column names. As mentioned above the order of values must correspond to column names in table.
1
|
insert into tbl_employee Values (005, ‘Ben’, 31, 3200.00, ‘2009/05/03’)
|
Leave A Comment?