Tüm Ürünler
Search
Belge Merkezi

Tablestore:Batch update data

Son Güncelleme:Oct 02, 2026

Tablestore PHP SDK'daki batchWriteRow yöntemini çağırarak birden çok tabloda verileri toplu olarak ekleyin, güncelleyin ve silin.

Kullanım notları

  • Sunucu herhangi bir işlemde parametre hatası algılarsa istekteki tüm işlemler başarısız olur.

  • Tek bir toplu güncelleme işlemi en fazla 200 satırı destekler. Tüm satırların toplam veri boyutu 4 MB'yi aşmamalıdır.

Ön koşullar

Tablestore istemcisini başlatın

Yöntem

public function batchWriteRow(array $request)

$request parametreleri

  • tables (Gerekli) array: Gerçekleştirilecek satır işlemleri. Bu parametre aşağıdaki alanları içerir.


    Ad


    Tür


    Açıklama


    table_name (Gerekli)


    string


    Veri tablosunun adı.


    rows (Gerekli)


    array


    Gerçekleştirilecek satır işlemleri. Desteklenen türler: write, update ve delete.

  • transaction_id (İsteğe bağlı) string: Yerel işlemin ID'si. Daha fazla bilgi için bkz. Yerel işlemler.

Örnekler

Aşağıdaki örnekte test_table tablosuna bir satır eklenir.

$table = array (
    'table_name' => 'test_table',
    'rows' => array (
        array (
            'operation_type' => OperationTypeConst::CONST_PUT,
            'primary_key' => array ( array('id', 'row1') )
        )
    )
);
$request = array(
    'tables' => array (
        $table
    )
);

try {
    // Call the batchWriteRow method to perform batch data operations.
    $response = $client->batchWriteRow ($request);

     // Process the response.
    foreach ($response['tables'] as $tableGroup) {
        foreach ($tableGroup['rows'] as $row) {
            if (!$row['is_ok']) {
                echo "TableName: {$tableGroup['table_name']}. ErrorCode: {$row['error']['code']}. ErrorMessage: {$row['error']['message']} \n";
            }
        }
    }
} catch (Exception $e){
    echo 'Batch write row failed.';
}

Aşağıdaki örnekler farklı işlem türlerini gösterir.

  • PutRowItem: Bir satır ekler.

    $table = array (
        'table_name' => 'test_table',
        'rows' => array (
            array (
                'operation_type' => OperationTypeConst::CONST_PUT,
                'primary_key' => array ( array('id', 'row1') )
            )
        )
    );

    Öznitelik sütunlarıyla birlikte bir satır ekler.

    $table = array (
        'table_name' => 'test_table',
        'rows' => array (
            array (
                'operation_type' => OperationTypeConst::CONST_PUT,
                'primary_key' => array ( array('id', 'row1') ),
                'attribute_columns' => array (
                    array('col1', 'val1'),
                    array('col2', 'val2', null, intval(microtime(true) * 1000))
                )
            )
        )
    );
  • UpdateRowItem: Öznitelik sütunu değerlerini değiştirerek, öznitelik sütunları ekleyerek veya belirli bir sürümü ya da öznitelik sütununun tüm sürümlerini silerek bir satırı günceller.

    $table = array (
        'table_name' => 'test_table',
        'rows' => array (
            array (
                'operation_type' => OperationTypeConst::CONST_UPDATE,
                'primary_key' => array ( array('id', 'row1') ),
                'update_of_attribute_columns'=> array(
                    'PUT' => array ( array('col1', 'changed_val1') )
                ),
                // A condition is required to update a row. RowExistenceExpectation.IGNORE skips the row existence check.
                'condition' => RowExistenceExpectationConst::CONST_IGNORE
            )
        )
    );

    Bir satırı güncellerken öznitelik sütunları ekler veya siler.

    $table = array (
        'table_name' => 'test_table',
        'rows' => array (
            array (
                'operation_type' => OperationTypeConst::CONST_UPDATE,
                'primary_key' => array ( array('id', 'row1') ),
                'update_of_attribute_columns'=> array(
                    'PUT' => array ( 
                        // Add an attribute column.
                        array('col3', 'val3'),
                        // Add an attribute column with a custom version number.
                        array('col4', 'val4', null, intval(microtime(true) * 1000))
                    ),
                    // Delete an attribute column.
                    'DELETE_ALL' => array('col2')
                ),
                // A condition is required to update a row. RowExistenceExpectation.IGNORE skips the row existence check.
                'condition' => RowExistenceExpectationConst::CONST_IGNORE
            )
        )
    );
  • DeleteRowItem: Bir satırı siler.

    $table = array (
        'table_name' => 'test_table',
        'rows' => array (
            array (
                'operation_type' => OperationTypeConst::CONST_DELETE,
                'primary_key' => array ( array('id', 'row1') ),
                // A condition is required to delete a row. RowExistenceExpectation.IGNORE skips the row existence check.
                'condition' => RowExistenceExpectationConst::CONST_IGNORE
            )
        )
    );

Kaynaklar