H2 Database 简明教程

H2 Database - Insert

SQL INSERT 语句用于将新行的数据添加到数据库中的表。

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

Syntax

以下是 INSERT INTO 语句的基本语法。

Following is the basic syntax of INSERT INTO statement.

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

使用这个 INSERT 语句,我们可以往表中插入一条新记录或多行新记录。当使用 DIRECT 子句时,结果会直接影响目标表,没有任何中间步骤。然而,在为表的所有列添加值的同时,确保值的顺序与表中的列相同。

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

Example

我们举一个例子,并尝试将以下给定的记录插入到 Customer 表中。

Let us take an example and try to insert the following given records into the Customer table.

ID

Name

Age

Address

Salary

1

Ramesh

32

Ahmedabad

2000

2

Khilan

25

Delhi

1500

3

Kaushik

23

Kota

2000

4

Chaitail

25

Mumbai

6500

5

Hardik

27

Bhopal

8500

6

Komal

22

MP

4500

7

Muffy

24

Indore

10000

我们可以通过执行以下命令将所有给定的记录放入 customer 表中。

We can get all the given records into the customer table by executing the following commands.

INSERT INTO CUSTOMER VALUES (1, 'Ramesh', 32, 'Ahmedabad', 2000);
INSERT INTO CUSTOMER VALUES (2, 'Khilan', 25, 'Delhi', 1500);
INSERT INTO CUSTOMER VALUES (3, 'kaushik', 23, 'Kota', 2000);
INSERT INTO CUSTOMER VALUES (4, 'Chaitali', 25, 'Mumbai', 6500);
INSERT INTO CUSTOMER VALUES (5, 'Hardik', 27, 'Bhopal', 8500);
INSERT INTO CUSTOMER VALUES (6, 'Komal', 22, 'MP', 4500);
INSERT INTO CUSTOMER VALUES (7, 'Muffy', 24, 'Indore', 10000);