

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 AWS Glue 或 Athena 主控台建立資料表
<a name="creating-tables-how-to"></a>

您可以使用 新增資料表表單 AWS Glue或在 Athena 查詢編輯器中執行 DDL 陳述式，在 Athena 中建立資料表。

## 使用 AWS Glue 爬蟲程式建立資料表
<a name="to-create-a-table-using-the-aws-glue-data-catalog"></a>

1. 前往 [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) 開啟 Athena 主控台。

1. 在查詢編輯器中，選擇位於**資料表和檢視**旁的**建立**，然後選擇 **AWS Glue 爬蟲程式**。

1. 請依照 AWS Glue 主控台 **Add crawler** (新增爬蟲程式) 頁面上的步驟新增爬蟲程式。

   如需詳細資訊，請參閱[使用編目程式新增資料表](schema-crawlers.md)。

## 使用 Athena 新增資料表表單來建立資料表
<a name="to-create-a-table-using-the-wizard"></a>

1. 前往 [https://console.aws.amazon.com/athena/](https://console.aws.amazon.com/athena/home) 開啟 Athena 主控台。

1. 在查詢編輯器中，選擇位在 **Tables and views** (資料表和檢視) 旁的 **Create** (建立)，然後選擇 **S3 bucket data** (S3 儲存貯體資料)。

1. 在 **Create Table From S3 bucket data** (從 S3 儲存貯體資料建立資料表) 表單中，輸入用於建立資料表的資訊，然後選擇 **Create table** (建立資料表)。如需表單欄位的詳細資訊，請參閱[使用 Athena 主控台中的表單來新增 AWS Glue 資料表](data-sources-glue-manual-table.md)。

## 在 Athena 查詢編輯器中，使用 CREATE TABLE 陳述式建立資料表
<a name="to-create-a-table-using-hive-ddl"></a>

1. 從 **Database (資料庫)** 選單中，選擇要為其建立資料表的資料庫。如果您未在 `CREATE TABLE` 陳述式中指定資料庫，則會在查詢編輯器中目前選取的資料庫中建立資料表。

1. 在查詢編輯器中，輸入下列範例所示的陳述式，然後選擇**執行**。

   ```
   CREATE EXTERNAL TABLE {{myopencsvtable}} (
      firstname string,
      lastname string,
      job string,
      country string
   )
   ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
   WITH SERDEPROPERTIES (
      'separatorChar' = ',',
      'quoteChar' = '"',
      'escapeChar' = '\\'
      )
   STORED AS TEXTFILE
   LOCATION 's3://{{amzn-s3-demo-bucket}}/{{mycsv}}/';
   ```