> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.cdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# UPSERT ステートメント

> UPSERT ステートメントは、既存のレコードを更新するか、既存のレコードが識別されない場合は新しいレコードを作成します。

## アップサートの設定

UPSERT の構文は INSERT と同じです。Connect AI は、データをアップサートする際に、テーブルの主キーを使用してレコードが存在するかどうかを判断することが多いです。ただし、データソース自体がアップサートをサポートしている場合は、データソースのアップサートロジックが使用されます。

以下は、Salesforce に Lead をアップサートする例です。この例では、Salesforce が Lead をアップサートする際のキーとして ExternalIdColumn を使用しています。

```bash theme={null}
UPSERT INTO Lead (FirstName, LastName, Company, External_Id_Column__c, ExternalIdColumn)
VALUES ('Bob', 'Thorton', 'Universal Pictures', 12345, 'External_Id_Column__c')
```
