すべてのプロダクト
Search
ドキュメントセンター

MaxCompute:テーブルの変更と表示

最終更新日:Jan 20, 2025

このトピックでは、SQL文を使用してテーブルを変更および表示する方法について説明します。

コマンド

コマンドカテゴリ

タイプ

説明

ロール

操作プラットフォーム

テーブルの変更

テーブルの所有者の変更

テーブルの所有者を変更します。

プロジェクト所有者

このトピックのコマンドは、次のプラットフォームを使用して実行できます。

テーブルのコメントの変更

テーブルのコメントを変更します。

テーブルに対するALTER権限を持つユーザー

テーブルの最終更新時刻の変更

テーブルのLastModifiedTimeを現在の時刻に変更します。

テーブルのクラスタリング属性の変更

クラスタリング属性をテーブルに追加または削除します。

テーブルの名前変更

テーブルの名前を変更します。

パーティション分割されていないテーブルからデータを消去する

指定された非パーティションテーブルからデータを消去します。

クリア列データ

標準テーブルの列をクリアします。

テーブルを見る

テーブル情報の表示

MaxComputeの内部テーブル、外部テーブル、クラスタ化テーブル、またはトランザクションテーブルに関する情報を表示します。

テーブルメタデータを読み取るためのDESCRIBE権限を持つユーザー

CREATE TABLEステートメントの表示

テーブルのDDLステートメントを表示します。

プロジェクト内のテーブルとビューの一覧表示

プロジェクト内のすべての内部テーブルと外部テーブル、または特定の条件を満たすテーブルを一覧表示します。

プロジェクトオブジェクトに対するLIST権限を持つユーザー

プロジェクト内の外部テーブルの一覧表示

プロジェクト内のすべての外部テーブル、または特定の条件を満たすテーブルを一覧表示します。

テーブルの所有者の変更

重要

プロジェクトの所有者またはSuper_Administratorロールを持つユーザーのみが、テーブルの所有者を変更するステートメントを実行できます。

構文

ALTER TABLE <table_name> CHANGEOWNER TO <new_owner>;

Parameters

パラメーター

必須 / 任意

説明

table_name

対象

変更する所有者のテーブルの名前。

new_owner

対象

テーブルの新しい所有者。 所有者をRAMユーザーに設定する場合は、RAM$<UID >:< ram_name> の形式を使用します。UIDはAlibaba CloudアカウントID、ram_nameはRAMユーザーの表示名です。

説明

テーブル所有者をRAMユーザーに設定するには、テーブルが存在するプロジェクトにRAMユーザーが追加されていることを確認します。

使用例

このトピックのサンプルデータは、sale_detailテーブルに作成されます。 詳細については、「」をご参照ください。パーティション分割テーブルを作成します。

  • sale_detailテーブルの所有者をALIYUN$xxx@aliyun.comに変更します。

    ALTER TABLE sale_detail CHANGEOWNER TO 'ALIYUN$xxx@aliyun.com';
  • sale_detailテーブルの所有者をRAM_testという名前のramユーザーに変更します。

    ALTER TABLE sale_detail CHANGEOWNER TO 'RAM$13xxxxxxxxxxx:ram_test';

テーブルのコメントの変更

構文

ALTER TABLE <table_name> SET COMMENT '<new_comment>';

Parameters

パラメーター

必須 / 任意

説明

table_name

対象

コメントを変更するテーブルの名前。

new_comment

対象

新しいコメント名。

使用例

ALTER TABLE sale_detail SET COMMENT 'new comment for table sale_detail';

MaxComputeのDESC <table_name> コマンドを使用して、テーブルの更新されたコメントを表示できます。

+------------------------------------------------------------------------------------+
| Owner:                    ALIYUN$sant****.aliyunid.com                  |
| Project:                  ani****                                               |
| Schema:                   default                                                  |
| TableComment: new comment for table sale_detail                                    |
+------------------------------------------------------------------------------------+

テーブルの最終更新時刻の変更

MaxCompute SQLは、テーブルのLastModifiedTimeを変更するTOUCH操作を提供します。 テーブルのLastModifiedTimeを現在の時刻に変更できます。 MaxComputeは、テーブル内のデータが変更されたと見なし、ライフサイクルの計算が再開されます。

構文

ALTER TABLE <table_name> TOUCH;

Parameters

table_name: 必須です。 LastModifiedTimeを変更するテーブルの名前。

使用例

ALTER TABLE sale_detail TOUCH;

テーブルのクラスタリング属性の変更

パーティションテーブルの場合、MaxComputeはALTER TABLEステートメントを使用してクラスタリング属性の追加または削除をサポートします。

構文

  • ハッシュクラスタリング属性をテーブルに追加します。

    ALTER TABLE <table_name> 
    [CLUSTERED BY (<col_name> [, <col_name>, ...]) 
    [SORTED BY (<col_name> [ASC | DESC] [, <col_name> [ASC | DESC] ...])] 
    INTO <number_of_buckets> BUCKETS];
  • ハッシュクラスタリング属性をテーブルから削除します。

    ALTER TABLE <table_name> NOT CLUSTERED;
  • 範囲クラスタリング属性をテーブルに追加します。 INTO <number_of_buckets> BUCKETS句はオプションです。 バケットの数を指定しない場合、MaxComputeはデータボリュームに基づいて最適な数を自動的に決定します。

    ALTER TABLE <table_name> 
    [RANGE CLUSTERED BY (<col_name> [, <col_name>, ...]) 
    [SORTED BY (<col_name> [ASC | DESC] [, <col_name> [ASC | DESC] ...])] 
    INTO <number_of_buckets> BUCKETS];
  • テーブルまたはパーティションから範囲クラスタリング属性を削除します。

    ALTER TABLE <table_name> NOT CLUSTERED;
    ALTER TABLE <table_name> <pt_spec> NOT CLUSTERED;
    説明
    • ALTER TABLEステートメントは、パーティションテーブルに対してのみ有効です。 クラスタリング属性がパーティション分割されていないテーブルに設定されると、変更することはできません。 ALTER TABLE文は既存のテーブルに適用されます。 新しいクラスタリング属性を追加した後、これらの属性に基づいて新しいパーティションが格納されます。

    • ALTER TABLEステートメントは、INSERT OVERWRITEによって生成されたパーティションを含む、パーティション分割テーブルの新しいパーティションにのみ影響します。 新しいパーティションは新しいクラスタリング属性に基づいて格納されますが、古いデータパーティションの格納は変更されません。 具体的には、既存のクラスタリング属性を持つテーブルの新しいパーティションに対して、異なるクラスタリング列、並べ替え列、およびバケット数を設定する場合は、まず既存のクラスタリング属性を削除してから、新しいクラスタリング属性を追加する必要があります。

    • ALTER TABLEステートメントは新しいパーティションにのみ影響するため、ステートメントでパーティションを指定することはできません。

Parameters

詳細については、「テーブルの作成と削除」をご参照ください。

テーブルの名前変更

テーブルの名前のみを変更します。 データは影響を受けません。

構文

ALTER TABLE <table_name> RENAME TO <new_table_name>;

Parameters

パラメーター

必須 / 任意

説明

table_name

対象

名前を変更するテーブル。

new_table_name

対象

テーブルの新しい名前。 new_table_nameと同じ名前のテーブルがすでに存在する場合は、エラーが返されます。

使用例

ALTER TABLE sale_detail RENAME TO sale_detail_rename;

テーブル情報の表示

MaxComputeの内部、外部、クラスタ、またはトランザクションテーブルに関する情報を取得します。 テーブルの詳細については、「SELECT構文」をご参照ください。

構文

  • テーブル情報を取得します。

    DESC <table_name> [PARTITION (<pt_spec>)]; 
  • 外部テーブル、クラスターテーブル、トランザクションテーブルに関する情報、または内部テーブルに関する拡張情報 (列のnull以外の属性など) を取得します。

    -- Retrieve the information about an external table, a clustered table, or a transactional table. You can also execute this statement to Retrieve the extended information about an internal table.
    DESC EXTENDED <table_name>; 

Parameters

パラメーター

必須 / 任意

説明

table_name

対象

表示するテーブルの名前。

pt_spec

非対象

表示するパーティションテーブルの指定されたパーティション。(partition_col1 = partition_col_value1, partition_col2 = partition_col_value2, ...) の形式です。

使用例

説明

以下の実施例におけるデータは実施例からのものである。

  • test1テーブルに関する情報を取得します。

    DESC test1;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$maoXXX@alibaba-inc.com | Project: $project_name                      |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2020-11-16 17:47:48                                      |
    | LastDDLTime:              2020-11-16 17:47:48                                      |
    | LastModifiedTime:         2020-11-16 17:47:48                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | key             | string     |       |                                             |
    +------------------------------------------------------------------------------------+
  • sale_detailテーブルに関する情報を取得します。

    DESC sale_detail;

    返される結果 :

    +--------------------------------------------------------------------+
    | Owner: ALIYUN$maoXXX@alibaba-inc.com | Project: $project_name      |
    | TableComment:                                                      |
    +--------------------------------------------------------------------+
    | CreateTime:               2017-06-28 15:05:17                      |
    | LastDDLTime:              2017-06-28 15:05:17                      |
    | LastModifiedTime:         2017-06-28 15:05:17                      |
    +--------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                  |
    +--------------------------------------------------------------------+
    | Native Columns:                                                    |
    +--------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                     |
    +--------------------------------------------------------------------+
    | shop_name       | string     |       |                             |
    | customer_id     | string     |       |                             |
    | total_price     | double     |       |                             |
    +--------------------------------------------------------------------+
    | Partition Columns:                                                 |    
    +--------------------------------------------------------------------+
    | sale_date       | string     |                                     |
    | region          | string     |                                     |
    +--------------------------------------------------------------------+
  • sale_detail_ctas1テーブルに関する詳細情報を取得します。

    DESC extended sale_detail_ctas1;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$maoXXX@alibaba-inc.com | Project: $project_name                      |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2021-07-07 15:29:53                                      |
    | LastDDLTime:              2021-07-07 15:29:53                                      |
    | LastModifiedTime:         2021-07-07 15:29:53                                      |
    | Lifecycle:                10                                                       |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | shop_name | string |       |               | true     | NULL         |              |
    | customer_id | string |       |               | true     | NULL         |              |
    | total_price | double |       |               | true     | NULL         |              |
    | sale_date | string |       |               | true     | NULL         |              |
    | region   | string |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  98cb8a38733c49eabed4735173818147                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    +------------------------------------------------------------------------------------+

    sale_dateおよびregionフィールドは、テーブル内のパーティションではなく、標準の列として機能します。

  • sale_detail_ctas2テーブルに関する情報を取得します。

    DESC sale_detail_ctas2;

    返される結果 :

    +--------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name       |
    | TableComment:                                                      |
    +--------------------------------------------------------------------+
    | CreateTime:               2017-06-28 15:42:17                      |
    | LastDDLTime:              2017-06-28 15:42:17                      |
    | LastModifiedTime:         2017-06-28 15:42:17                      |
    +--------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                  |
    +--------------------------------------------------------------------+
    | Native Columns:                                                    |
    +--------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                     |
    +--------------------------------------------------------------------+
    | shop_name       | string     |       |                             |
    | customer_id     | string     |       |                             |
    | total_price     | double     |       |                             |
    | sale_date       | string     |       |                             |
    | region          | string     |       |                             |
    +--------------------------------------------------------------------
  • sale_detail_likeテーブルに関する詳細情報を取得します。

    DESC extended sale_detail_like;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name                       |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2021-07-07 15:40:38                                      |
    | LastDDLTime:              2021-07-07 15:40:38                                      |
    | LastModifiedTime:         2021-07-07 15:40:38                                      |
    | Lifecycle:                10                                                       |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | shop_name | string |       |               | true     | NULL         |              |
    | customer_id | string |       |               | true     | NULL         |              |
    | total_price | double |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | sale_date       | string     |                                                     |
    | region          | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  61782ff7713f426e9d6f91d5deeac99a                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    +------------------------------------------------------------------------------------

    ライフサイクル属性とは別に、フィールドとパーティションタイプを含むsale_detail_likeの他のすべての属性は、sale_detailの属性と正確に一致します。

    説明

    DESC <table_name>; によって示されるサイズは、ごみ箱内のデータを含む。 ごみ箱を空にするには、まずPURGE TABLE <table_name>; を実行します。 その後、DESC <table_name>; を再度実行して、ごみ箱の内容なしでデータサイズを確認します。 プロジェクトのごみ箱の内容を確認するには、SHOW recyclebin; を使用します。

  • test_newtypeテーブルに関する情報を取得します。

    DESC test_newtype;

    返される結果 :

    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | c1              | tinyint    |       |                                             |
    | c2              | smallint   |       |                                             |
    | c3              | int        |       |                                             |
    | c4              | bigint     |       |                                             |
    | c5              | float      |       |                                             |
    | c6              | double     |       |                                             |
    | c7              | decimal    |       |                                             |
    | c8              | binary     |       |                                             |
    | c9              | timestamp  |       |                                             |
    | c10             | array<map<bigint,bigint>> |       |                              |
    | c11             | map<string,array<bigint>> |       |                              |
    | c12             | struct<s1:string,s2:bigint> |       |                            |
    | c13             | varchar(20) |       |                                            |
    +------------------------------------------------------------------------------------
    
    OK
  • 拡張情報のクラスタリング属性を使用して、ハッシュクラスタ化テーブルt1に関する情報を取得します。

    DESC extended t1;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name                       |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2020-11-16 18:00:56                                      |
    | LastDDLTime:              2020-11-16 18:00:56                                      |
    | LastModifiedTime:         2020-11-16 18:00:56                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  e6b06f705dc34a36a5b72e5af486cab7                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | ClusterType:              hash                                                     |
    | BucketNum:                1024                                                     |
    | ClusterColumns:           [c]                                                      |
    | SortColumns:              [c ASC]                                                  |
    +------------------------------------------------------------------------------------
    
    OK
  • 拡張情報のクラスタリング属性を使用して、ハッシュクラスタ化パーティションテーブルt2に関する情報を取得します。

    DESC EXTENDED t2;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name                       |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime: 2017-12-25 11:18:26                                                    |
    | LastDDLTime: 2017-12-25 11:18:26                                                   |
    | LastModifiedTime: 2017-12-25 11:18:26                                              |
    | Lifecycle: 2                                                                       |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES | Size: 0                                                       |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field | Type   | Label | Comment                                                   |
    +------------------------------------------------------------------------------------+
    | a     | string |       |                                                           |
    | b     | string |       |                                                           |
    | c     | bigint |       |                                                           |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | dt    | string |                                                                   |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID: 91a3395d3ef64b4d9ee1d2852755                                              |
    | IsArchived: false                                                                  |
    | PhysicalSize: 0                                                                    |
    | FileNum: 0                                                                         |
    | ClusterType: hash                                                                  |
    | BucketNum: 1024                                                                    |
    | ClusterColumns: [c]                                                                |
    | SortColumns: [c ASC]                                                               |
    +------------------------------------------------------------------------------------
    
    OK
  • 拡張情報のクラスタリング属性を使用して、範囲クラスタ化テーブルt3に関する情報を取得します。

    DESC extended t3;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name                       |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2020-11-16 18:01:05                                      |
    | LastDDLTime:              2020-11-16 18:01:05                                      |
    | LastModifiedTime:         2020-11-16 18:01:05                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  38d170aca2684f4baadbbe1931a6ae1f                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | ClusterType:              range                                                    |
    | BucketNum:                1024                                                     |
    | ClusterColumns:           [c]                                                      |
    | SortColumns:              [c ASC]                                                  |
    +------------------------------------------------------------------------------------
    
    OK
  • 拡張情報のクラスタリング属性を使用して、範囲クラスタ化パーティションテーブルt4に関する情報を取得します。

    DESC extended t4;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@alibaba-inc.com | Project: $project_name                       |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2020-11-16 19:17:48                                      |
    | LastDDLTime:              2020-11-16 19:17:48                                      |
    | LastModifiedTime:         2020-11-16 19:17:48                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | a        | string |       |               | true     | NULL         |              |
    | b        | string |       |               | true     | NULL         |              |
    | c        | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | dt              | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------+
    | TableID:                  6ebc3432e283449188c861427bcd6ee4                         |
    | IsArchived:               false                                                    |
    | PhysicalSize:             0                                                        |
    | FileNum:                  0                                                        |
    | StoredAs:                 AliOrc                                                   |
    | CompressionStrategy:      normal                                                   |
    | ClusterType:              range                                                    |
    | BucketNum:                0                                                        |
    | ClusterColumns:           [c]                                                      |
    | SortColumns:              [c ASC]                                                  |
    +------------------------------------------------------------------------------------
    
    OK
  • 非パーティションテーブルt5がトランザクションであるかどうかを確認します。

    説明

    MaxComputeクライアント (odpscmd) を使用してトランザクションテーブルを確認することを推奨します。 古いツールはトランザクション情報を表示しない可能性があるため、クライアントがV0.35.4以降に更新されていることを確認します。

    DESC extended t5;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@aliyun.com | Project: $project_name                            |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2021-02-18 10:56:27                                      |
    | LastDDLTime:              2021-02-18 10:56:27                                      |
    | LastModifiedTime:         2021-02-18 10:56:27                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field    | Type   | Label | ExtendedLabel | Nullable | DefaultValue | Comment      |
    +------------------------------------------------------------------------------------+
    | id       | bigint |       |               | true     | NULL         |              |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------
    ...
    | Transactional:            true                                                     |
    +------------------------------------------------------------------------------------
  • パーティションテーブルt6がトランザクションであるかどうかを確認する。

    説明

    MaxComputeクライアント (odpscmd) を使用してトランザクションテーブルを確認することを推奨します。 古いツールはトランザクション情報を表示しない可能性があるため、クライアントがV0.35.4以降に更新されていることを確認します。

    DESC extended t6;

    返される結果 :

    +------------------------------------------------------------------------------------+
    | Owner: ALIYUN$xxxxx@test.aliyunid.com | Project: $project_name                     |
    | TableComment:                                                                      |
    +------------------------------------------------------------------------------------+
    | CreateTime:               2021-02-18 15:34:54                                      |
    | LastDDLTime:              2021-02-18 15:34:54                                      |
    | LastModifiedTime:         2021-02-18 15:34:54                                      |
    +------------------------------------------------------------------------------------+
    | InternalTable: YES      | Size: 0                                                  |
    +------------------------------------------------------------------------------------+
    | Native Columns:                                                                    |
    +------------------------------------------------------------------------------------+
    | Field           | Type       | Label | Comment                                     |
    +------------------------------------------------------------------------------------+
    | id              | bigint     |       |                                             |
    +------------------------------------------------------------------------------------+
    | Partition Columns:                                                                 |
    +------------------------------------------------------------------------------------+
    | ds              | string     |                                                     |
    +------------------------------------------------------------------------------------+
    | Extended Info:                                                                     |
    +------------------------------------------------------------------------------------
    ...
    | Transactional:            true                                                     |
    +------------------------------------------------------------------------------------

CREATE TABLEステートメントの表示

この機能は、テーブルの作成に使用されるSQL文を表示し、テーブルのスキーマをレプリケートできるようにします。

構文

SHOW CREATE TABLE <table_name>;

Parameters

table_name: 必須です。 CREATE tableステートメントを表示するテーブルの名前を指定します。

使用例

-- View the CREATE TABLE statement of the sale_detail table.
SHOW CREATE TABLE sale_detail;

返される結果 :

CREATE TABLE IF NOT EXISTS max****.`default`.sale_detail(shop_name STRING, customer_id STRING, total_price DOUBLE) 
PARTITIONED BY (sale_date STRING, region STRING) STORED AS ALIORC TBLPROPERTIES ('columnar.nested.type'='true');

プロジェクト内のテーブルとビューの一覧表示

プロジェクト内のすべてのテーブル、外部テーブル、ビュー、およびマテリアライズドビュー、または特定の条件を満たすビューのリストを取得します。

構文

-- List all tables and views in a project.
SHOW TABLES;
-- List the tables or views whose names contain the chart keyword in a project.
SHOW TABLES LIKE '<chart>';

使用例

-- List the tables whose names contain the sale* keyword in a project. The asterisk (*) indicates any character.
SHOW TABLES LIKE 'sale*';              

返される結果 :

ALIYUN$account_name:sale_detail
......
-- ALIYUN is a system prompt, which indicates that the table is created by using an Alibaba Cloud account. If you are a RAM user, the system prompt is RAM.

プロジェクト内の外部テーブルの一覧表示

プロジェクト内のすべての外部テーブル、または特定の条件を満たす外部テーブルのリストを取得します。

説明

SHOW EXTERNAL TABLESコマンドを使用するには、MaxComputeクライアント (odpscmd) V0.43.0以上で操作していることを確認します。

構文

-- List all external tables in a project.
SHOW EXTERNAL TABLES;
-- View the external tables whose names match the condition specified by external_chart in a project.
SHOW EXTERNAL TABLES LIKE '<external_chart>';

使用例

-- View the external tables whose names match the condition specified by a* in a project. The asterisk (*) indicates any character.
SHOW EXTERNAL TABLES LIKE 'a*';   

返される結果 :

ALIYUN$account_name:a_et
......
-- ALIYUN is a system prompt, which indicates that the table is created by using an Alibaba Cloud account. If you are a RAM user, the system prompt is RAM.

パーティション分割されていないテーブルからデータを消去する

指定された非パーティションテーブルからデータをクリアします。 パーティションテーブルの単一のパーティションまたは複数のパーティションからデータをクリアするには、「パーティションからデータをクリアする」をご参照ください。

構文

TRUNCATE TABLE <table_name>;

Parameters

table_name: 必須です。 削除するパーティション分割されていないテーブルの名前。

クリア列データ

clear columnコマンドは、標準テーブルの特定の列からデータを削除するために使用します。 ディスクから未使用の列データを削除し、列をNULLに設定することで、ストレージコストを削減できます。

構文

ALTER TABLE <table_name> [partition ( <pt_spec>[, <pt_spec>....] )] 
  CLEAR COLUMN column1[, column2, column3, ...] 
  [without touch];

Parameters

パラメーター

必須 / 任意

説明

table_name

対象

列データを消去するテーブルの名前。

column

対象

クリアする列の名前。

partition

非対象

パーティションを指定します。 指定しない場合、操作はすべてのパーティションに影響します。

pt_spec

非対象

パーティション仕様は、(partition_col1 = partition_col_value1, partition_col2 = partition_col_value2, ...) の形式です。

without touch

非対象

LastDataModifiedTimeを更新しないことを指定します 省略した場合、LastDataModifiedTimeは自動的に更新されます

使用例

-- Add partitions to the sale_detail table
ALTER TABLE sale_detail ADD PARTITION (sale_date='2023', region='china') PARTITION (sale_date='2024', region='shanghai');

-- Insert data into the partitioned table
INSERT INTO sale_detail PARTITION (sale_date='2023', region='china') VALUES ('s1','c1',100.1),('s2','c2',100.2),('s3','c3',100.3);
INSERT INTO sale_detail PARTITION (sale_date='2024', region='shanghai') VALUES ('null','c5',null),('s6','c6',100.4),('s7','c7',100.5);

-- Clear data from the shop_name column
ALTER TABLE sale_detail partition(sale_date='2023', region='china') CLEAR COLUMN shop_name;

列データのクリアの制限と例の詳細については、「列からデータをクリアする」をご参照ください。

関連ドキュメント