Skip to content

3.2 DDL (ALTER TABLE)

Peng Ren edited this page Oct 15, 2022 · 4 revisions

Syntax

ALTER TABLE tbl_name (
    [col_name column_definition, ...]
    [alter_option [, alter_option] ...]
)
    [table_options]

alter_option: {
    CREATE INDEX [index_name] GLOBAL
        (col_name key_type, ...)
        [index_option] ...
    | UPDATE INDEX [index_name] GLOBAL
        [index_option] ...
    | DELETE INDEX [index_name] GLOBAL
    | CREATE REPLICA [region_name]
        [replica_option] ...
    | UPDATE REPLICA [region_name]
        [replica_option] ...
    | DELETE REPLICA [region_name]
}

key_type : {
    PARTITION KEY | SORT KEY | HASH | RANGE
}

index_option: {
    Projection.ProjectionType [=] {ALL | KEYS_ONLY | INCLUDE}
    | Projection.NonKeyAttributes [=] ('string', ...)
    | ProvisionedThroughput.ReadCapacityUnits [=] value
    | ProvisionedThroughput.WriteCapacityUnits [=] value
}

replica_option: {
    KMSMasterKeyId [=] value
    | ProvisionedThroughputOverride.ReadCapacityUnits [=] value
    | TableClassOverride [=] {STANDARD | STANDARD_INFREQUENT_ACCESS}
    | GlobalSecondaryIndexes [=] (
        index_name [ProvisionedThroughputOverride.ReadCapacityUnits [=] value],
        ...)
}

table_options:
    table_option [[,] table_option] ...

table_option: {
    BillingMode [=] {PROVISIONED | PAY_PER_REQUEST}
    | ProvisionedThroughput.ReadCapacityUnits [=] value
    | ProvisionedThroughput.WriteCapacityUnits [=] value
    | StreamSpecification.StreamEnabled [=] {True | False}
    | StreamSpecification.StreamViewType [=] {NEW_IMAGE | OLD_IMAGE | NEW_AND_OLD_IMAGES | KEYS_ONLY}
    | SSESpecification.Enabled [=] {True | False}
    | SSESpecification.SSEType [=] {AES256 | KMS}
    | SSESpecification.KMSMasterKeyId [=] value
    | TableClass [=] {STANDARD | STANDARD_INFREQUENT_ACCESS}
}

Sample

ALTER TABLE Issues (
    IssueId numeric,
    Title string,
    CreateDate string,
    DueDate string,
    CREATE INDEX CreateDateIndex GLOBAL (
        CreateDate PARTITION KEY,
        IssueId SORT KEY
    )
        Projection.ProjectionType INCLUDE
        Projection.NonKeyAttributes (Description, Status)
        ProvisionedThroughput.ReadCapacityUnits 1
        ProvisionedThroughput.WriteCapacityUnits 1,
    UPDATE INDEX DueDateIndex GLOBAL
        ProvisionedThroughput.ReadCapacityUnits 10
        ProvisionedThroughput.WriteCapacityUnits 10,
    DELETE INDEX IssueIdIndex GLOBAL,
    CREATE REPLICA cn-north-1
        KMSMasterKeyId XXXXXXXX
        ProvisionedThroughputOverride.ReadCapacityUnits 1
        GlobalSecondaryIndexes (
            CreateDateIndex
            ProvisionedThroughputOverride.ReadCapacityUnits 1,
            DueDateIndex
            ProvisionedThroughputOverride.ReadCapacityUnits 1
        )
        TableClassOverride STANDARD,
    UPDATE REPLICA cn-northwest-1
        KMSMasterKeyId *********
        ProvisionedThroughputOverride.ReadCapacityUnits 10
        GlobalSecondaryIndexes (
            CreateDateIndex
            ProvisionedThroughputOverride.ReadCapacityUnits 10,
            DueDateIndex
            ProvisionedThroughputOverride.ReadCapacityUnits 10
        )
        TableClassOverride STANDARD_INFREQUENT_ACCESS,
    DELETE REPLICA cn-northwest-2
)
BillingMode PAY_PER_REQUEST
ProvisionedThroughput.ReadCapacityUnits 10
ProvisionedThroughput.WriteCapacityUnits 10
StreamSpecification.StreamEnabled True
StreamSpecification.StreamViewType NEW_AND_OLD_IMAGES
SSESpecification.Enabled True
SSESpecification.SSEType KMS
SSESpecification.KMSMasterKeyId $$$$$$$$
TableClass STANDARD_INFREQUENT_ACCESS

Reference

Please refer to boto3 API: DynamoDB.Client.update_table

Clone this wiki locally