Firebird Database statement: updateorinsert

Source: Internet
Author: User
Tags firebird database
Updateorinsert is a statement added in Firebird2.1. In this statement, you can determine whether a specific record exists in the target table based on the matching field. If no matching record exists, execute Insert, otherwise, other fields except matching fields are updated. The matched field must be the primary key. If you are using a trigger or stored procedure, you can also use the Re

Update or insert is a statement added in Firebird2.1. In this statement, you can determine whether a specific record exists in the target table based on the matching field. If no matching record exists, execute Insert, otherwise, other fields except matching fields are updated. The matched field must be the primary key. If you are using a trigger or stored procedure, you can also use the Re

Update or insert is a statement added in Firebird2.1. In this statement, you can determine whether a specific record exists in the target table based on the matching field. If no matching record exists, execute Insert, otherwise, other fields except matching fields are updated. The matched field must be the primary key. If it is used in a trigger or stored procedure, you can use the Returning clause to return a specific value to the variable.

This document describes the following:

UPDATE OR INSERT INTO   {tablename | viewname} [(
 
  )]   VALUES (
  
   )   [MATCHING (
   
    )]   [RETURNING 
    
      [INTO 
     
      ]]
      
        ::= colname [, colname ...]
       
         ::= value [, value ...]
        
          ::= :varname [, :varname ...]
        
       
      
     
    
   
  
 

A simple example:

Update or insert into khinfo (kh_code, kh_name) values ('000000', 'kunming XXX Co., Ltd. ') matching (kh_code)

Note: The Update or insert statement is used to determine whether to add a new record to the khinfo table. The matching condition is the primary key field kh_code. The execution result is processed based on whether the KH_Code exists or not.

This statement combines the Insert or Update statements that previously created two conditions into one statement to determine whether the primary key exists, the Firebird Database completes the judgment and execution of insert or Update operations, which is very concise.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.