カスタムクエリ: REPLICATE コマンド

Version 26.1.9516


カスタムクエリ: REPLICATE コマンド

Version 26.1.9516


CData Sync は、特別な目的のSQL コマンドであるREPLICATE を使用して、宣言的な方法ですべての変換を管理します。REPLICATE コマンドを使用すると、選択されるデータや適用される変換を定義し、同期先テーブルにデータをマッピングできます。

Note:Sync アプリケーションは、標準SQL クエリをソースAPI 呼び出しに動的に変換する完全なSQL-92 準拠エンジンを搭載しています。

REPLICATE 構文:

REPLICATE { 
  DestinationTableName
  (ColumnDefinition [ , ... ] [TableConstraint])
  [WITH {OptionName=OptionValue|OptionName} , ... ]
  { SelectStatement | TableReference> } 
}

ColumnDefinition := ColumnName DataType
TableConstraint := PRIMARY KEY(ColumnName,...)
OptionName := DropTable | TruncateTable | AlterSchema ...
OptionValue := Literal | Identifier

一般的なREPLICATE タスク

This section provides examples for several common REPLICATE tasks.

Maintain a Copy of a Table in Your Destination

If you want to maintain a copy of a table in your destination, you can use the following REPLICATE command:

REPLICATE Table

このREPLICATE コマンドは、同期先データベース内にテーブルを作成します(まだ存在しない場合)。該当する場合は、REPLICATE ステートメントは最近の変更(データソースで新しく更新または挿入されたレコード)を取得して、それらを同期先に適用します。

Replicate One Table from Another Table

You can use the following command to replicate one table from another table (in this case, replicating REP_Table from Table).

REPLICATE REP_Table SELECT * FROM Table

Select Columns and Perform Operations on Data before Replication

To select specific columns and perform operations on data before it is replicated, you can use the following REPLICATE command:

REPLICATE REP_Table SELECT DateModified, CONCAT(FirstName,' ',LastName) AS FullName FROM Table WHERE FirstName LIKE '%Tim%'

このコマンドは、DateModified カラムとFullName カラムを使用してテーブルREP_Table を作成します。FullName カラムは、Table テーブルのFirstName とLastName を連結したカラムです。

Replicating Tables in a Destination with and without a Primary Key

You can customize how Sync creates tables in your destination by redefining columns in the REPLICATE statement. This approach allows you to control whether to include or omit primary keys when a table is created in a destination.

To create a destination table without a primary key, even when one exists in the source, you can explicitly define the column without the PRIMARY KEY keyword in the column definition, as shown in this syntax:

REPLICATE [Table] (KeyColumnName int)

For example, to create a table named Airlines without the Id column as a primary key, submit this command:

REPLICATE Airlines (Id int)

To define a primary key in the destination, even when one does not exist in the source, use the same syntax but include the PRIMARY KEY keyword in the column definition, as shown here:

REPLICATE Airlines (Id int PRIMARY KEY)