Skip to content

Insert Statement

The insert_statement node represents a SQL INSERT statement, which adds new rows of data into a table.

Structure

 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
<xs:element name="insert_statement">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="cte_list" type="cte_list_type" minOccurs="0"/>
            <xs:element name="target_table" type="table_reference_type"/>
            <xs:element name="column_list" type="objectName_list_type" minOccurs="0" maxOccurs="unbounded"/>
            <xs:choice>
                <xs:element name="insert_values">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="row_values" type="expression_list_type" maxOccurs="unbounded"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="insert_query" type="query_expression_type"/>
                <xs:element name="insert_execute">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element ref="execute_statement"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="insertSource" type="xs:string"/>
    </xs:complexType>
</xs:element>

Elements

Element Type Description
cte_list cte_list_type Represents a Common Table Expression (CTE). Optional.
target_table table_reference_type The table to insert data into. Required.
column_list objectName_list_type The list of columns to populate. Optional.
insert_values Specifies one or more rows of values to be inserted.
insert_query query_expression_type A SELECT query that provides the rows to be inserted.
insert_execute An EXECUTE statement that provides the data.

Attributes

Attribute Type Description
insertSource xs:string Indicates the source of the inserted data (values, select, execute).

Example

 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
34
<statement type="insert_statement" insertSource="values">
  <target_table type="named_table_reference">
    <named_table_reference>
      <table_name>
        <full_name>employees</full_name>
        <object_name>employees</object_name>
      </table_name>
    </named_table_reference>
  </target_table>
  <column_list>
    <objectName>
      <full_name>id</full_name>
      <object_name>id</object_name>
    </objectName>
    <objectName>
      <full_name>name</full_name>
      <object_name>name</object_name>
    </objectName>
  </column_list>
  <insert_values>
    <row_values>
      <expression expr_type="constant_expr">
        <literal>
          <value>1</value>
        </literal>
      </expression>
      <expression expr_type="constant_expr">
        <literal>
          <value>'John Doe'</value>
        </literal>
      </expression>
    </row_values>
  </insert_values>
</statement>