H2 Database - Insert

H2 Database - Insert

The SQL INSERT statement is used to add new rows of data to a table in a database.

Syntax

Following is the basic syntax of the INSERT INTO statement.

INSERT INTO tableName
{ [ ( columnName [,...] ) ]
{ VALUES
{ ( { DEFAULT | expression } [,...] ) } [,...] | [ DIRECT ] [ SORTED ] select } } |
{ SET { columnName = { DEFAULT | expression } } [,...] }

Using this INSERT statement, we can insert a new record or new rows into the table. When using the DIRECT clause, the results directly affect the target table without any intermediate step. However, when adding values ​​for all columns in a table, make sure that the order of the values ​​is in the same order as the columns in the table.

example

Let's take an example and try to insert the following data into the Customer table.

I'D title Age The address Salary
one Ramesh 32 Ahmedabad 2000
2 Khilan 25 Delhi 1500
3 kaushik 23 Kota 2000
4 chataille 25 Mumbai 6500
5 hardik 27 Bhopal 8500
6 Komal 22 member of parliament 4500
7 Muffy 24 Indore 10000

We can get all record data in the customers table by running the following commands.