DEV Community

wanglei
wanglei

Posted on

INSERT INTO Statement

A new table contains no data. You need to insert data to the table before using it. You can execute the INSERT INTO statement to insert data into the table. This statement can be used to insert a row of data or multiple rows of data at the same time.

Syntax

Image description
Parameter Description
table_name

Specifies the name of the target table where data will be inserted.

Value range: an existing table name

column_name

Specifies the name of a column in the target table.

The column name can be qualified with a subcolumn name or an array subscript, if needed.
Each column not present in the column list will be filled with a default value, either its declared default value or NULL if there is none. Inserting data into only some columns of a composite type leaves the other columns NULL.
The target column names (specified by column_name) can be listed in any order. If no list of column names is given at all, the default is all the columns of the table in their declared order.
The target columns are the first N column names, if there are only N columns provided by the value clause.
The values provided by the value clause are associated with the corresponding columns from left to right in the table.
Value range: an existing column

expression

Specifies an expression or a value to assign to the corresponding column.

If single-quotation marks are inserted in a column, the single-quotation marks need to be used for escape.
If the expression for any column is not of the correct data type, automatic type conversion will be attempted. If the attempt fails, data insertion fails, and the system returns an error message.
DEFAULT

Specifies the default value of a column. The value is NULL if no specified default value has been assigned to it.

Examples

Image description

Top comments (0)