Todos los productos
Search
Centro de documentos

ApsaraDB for OceanBase (Deprecated):Crear una tabla

Última actualización: Sep 04, 2026

Este tema describe cómo crear una tabla en la consola de ODC.

Background information

OceanBase Developer Center (ODC) permite crear una tabla mediante una interfaz gráfica.

Create an internal table

image

El procedimiento comprende siete pasos:

  1. Especifique la información básica.

  2. Cree una tabla.

  3. Establezca los índices. (Opcional)

  4. Establezca las restricciones. (Opcional)

  5. Establezca las reglas de particionamiento. (Opcional)

  6. Compruebe la sentencia SQL.

  7. Complete la creación de la tabla.

Create an external table

An external table is a logical table object. Its data is stored in an external storage system instead of the database. For more information about external tables, see Descripción general.

ODC V4.3.3 and later allow you to create an external table by executing SQL statements in the SQL window, and to map an external file to a database managed by ODC by specifying the file path. You can view the existing external tables in the resource tree of the SQL window. For more information, see Crear una tabla externa.

You can use the CREATE EXTERNAL TABLE statement to create an external table.

Importante
  • External tables are read-only. You can query an external table, but cannot perform DML operations on external tables.
  • You need to specify the secure_file_priv variable before you create an external table in ODC by using a local file. To specify the variable, you can connect to OceanBase Database only by using a local Unix socket. ODC does not support this connection method, and you must use obclient to configure the connection. For more information, see secure_file_priv.

  1. Create an external file.
  2. Create an external table in the SQL window of ODC by executing SQL statements.
  3. View the external table in the resource tree.

Procedure

Crear una tabla en la base de datos física

In the following example, a table named employee is created in the ODC console. The table contains the emp_no,birthday, name, and gender columns.

Nota

Los datos utilizados en este tema son ejemplos. Puede reemplazarlos con datos reales según sea necesario.

Step 1: Specify the basic information

  1. Log on to the ODC console and click the name of the desired connection to go to the corresponding connection management page. You can click Table in the left-side navigation pane to view tables. To create a table, click the plus sign (+) in the upper-right corner of the table list or click Create in the top navigation bar.

  2. In the Basic Info section, set the Table Name and Description parameters.

    image.png

    Nota
    • In MySQL mode, you also need to set theDefault Character SetandDefault Collationparameters.
    • After you specify the basic information and go to the "Set columns" step, the basic information is submitted.

Step 2: Set columns

Nota

In ODC V4.2.3 and later, you can create a table that contains columns of spatial data types in OceanBase Database en modo MySQL or MySQL Database.

The following figure and table show the information that you need to specify when you add a column.

image

The following table describes operations that you can perform on the column setting page.

Operación

Descripción

Operaciones de la barra de herramientas

Puede agregar o eliminar columnas mediante la barra de herramientas superior de la página.

Hacer clic en un ID de fila

  • Puede hacer clic en un ID de fila para seleccionar la fila y mostrar un menú contextual que le permite agregar o eliminar la fila.

  • Puede hacer clic en un número de fila para seleccionarla y luego arrastrarla para ajustar el orden de toda la fila.

Hacer clic derecho en una fila

Puede hacer clic derecho en una fila para seleccionarla y luego elegir Copiar o Mover hacia abajo en el menú contextual que aparece.

Nota
  • After you copy a row, you can paste the row by using theCommand + VorCtrl + Vshortcut keys.
  • The auxiliary editing section at the bottom of the page displays additional information about the selected column.
  • The basic information and column settings are required. The settings in other configuration steps are optional. After you specify the basic information and column settings, you can submit the settings and confirm the SQL statement to create the table.

Step 3: Set indexes

If a table contains a large amount of data, you can use indexes to accelerate data queries. An index is a data structure that pre-sorts the values of one or more columns in a table. By using indexes, you can directly locate records that meet the conditions.

The following figure and table show the information that you need to specify when you set an index.

image

The index setting page provides the following icons.

Icono

Descripción

Create

Click this icon to create an index.

Delete

Click this icon to delete the selected index.

Step 4: Set constraints

Constraints are used to specify data rules for a table. A data operation that violates the constraints is terminated.

image

ODC supports the following four types of table constraints:

  • PRIMARY KEY constraint: defines a primary key to uniquely identify each row of data in the table. A PRIMARY KEY constraint can be a field or a group of fields. You can set only one PRIMARY KEY constraint for a table, and you cannot modify the PRIMARY KEY constraint after you configure the constraint.

  • UNIQUE constraint: ensures that the data in a field or a group of fields is unique in the table. You can set multiple UNIQUE constraints in one table.

  • FOREIGN KEY constraint: associates one or more columns in two tables. A FOREIGN KEY constraint is used to maintain the data consistency and integrity between associated tables. After you complete the setting of FOREIGN KEY constraints, you cannot create new constraints or modify existing constraints.

  • CHECK constraints: checks the data in the database based on the configured check rules when you edit the data. Data modification is allowed only after the check is passed.

OceanBase Database supports different constraints in MySQL and Oracle modes, and different constraints require different information. Therefore, you need to specify the required information based on the constraint you selected and the requirements on the page.

The constraint setting page provides the following icons.

Icono

Descripción

Create

Click this icon to create a constraint.

Delete

Click this icon to delete the selected constraint.

Step 5: Set partitioning rules

image

You can partition a table that contains a large amount of data. After a table is partitioned, data in the table is stored in multiple tablespaces. The database does not scan the entire table for a query.

  • In MySQL mode, OceanBase Database supports the following partitioning methods: KEY, HASH, RANGE, RANGE COLUMNS, LIST, and LIST COLUMNS.

  • In Oracle mode, OceanBase Database supports the following three partitioning methods: List, Range, and Hash.

Step 6: Confirm the SQL statement

image.png

After you click Execute, you can view the statement on the SQL confirmation page. You can check and format the statement.

The syntax is as follows:

CREATE TABLE table_name (column_name column_type, column_name column_type,.......);

The following table describes the fields in the syntax.

Campo

Descripción

CREATE TABLE

The keyword that indicates the creation of a table with a specified name. You must have the permission to create tables.

table_name

The name of the table. The table name must conform to the identifier naming rules.

column_name column_type

The name and data type of each column in the table. Separate the tuples of multiple columns with commas (,).

Step 7: Complete the table creation

Click Execute. After the table is created, the employee table appears in the table list in the left-side navigation pane.

image.png

Nota

You can click the More icon next to a table name in the table list in the left-side navigation pane, and select View Table Schema, View Table Data, Import, Export, Download, Mock Data, Open SQL Window, Copy, Delete, or Refresh from the context menu to manage or operate the table.

For more information, see Table attribute management.

You can use the SELECT statement to query data in the new table.

The syntax is as follows:

SELECT
 column_name,
 column_name
FROM
 table_name [WHERE Clause] [LIMIT N] [ OFFSET M]

The following table describes the fields in the syntax.

Campo

Descripción

SELECT

The keyword that indicates the name of the statement. You can use the SELECT statement to read one or more records.

column_name

The name of the column to be queried. You can use an asterisk (*) in the format of * to query all columns

WHERE

The keyword of the condition clause.

LIMIT

The number of records to be returned.

OFFSET

The data offset from which the SELECT statement starts to query. The default offset is 0.

Here is an example:

SELECT `emp_no`, `birthdate`, `name`, `gender` FROM `employee`;

image.png

Create an external table

The example in this section describes how to create an external table named employee in the odc_test database managed by ODC in the SQL window by mapping the specified file in Alibaba Cloud Object Storage Service (OSS) to the odc_test database.

  1. Create an external file.
    1. Create a directory named external table on the Log on to the OSS console with an Alibaba Cloud account.

      image

    2. Upload the employee.csv file to the external table directory.

      image

    3. Copy the path of the employee table, such as https://ob*********.oss-cn-shanghai.aliyuncs.com/doc/img/odc/433/external%20table/employee.csv.

      image

  2. In the SQL window of ODC, execute the following SQL statement to create an external table named employee.

    image

    CREATE EXTERNAL TABLE `employee` (
       `emp_no` int(120),
       `birthday` date,
       `name` varchar(120)
    )
       LOCATION = 'ob*********.oss-cn-shanghai.aliyuncs.com/doc/img/odc/433/500.sql-development/700.database-objects/100.web-odc-table-objects/employee/employee.csv'
       FORMAT = (
          TYPE = 'CSV'
          FIELD_DELIMITER = ','
          FIELD_OPTIONALLY_ENCLOSED_BY ='"'
          ENCODING = 'utf8mb4'
          )
       PATTERN = 'employee.csv';
    
    • The LOCATION option specifies the path for storing the external table.

      • Local location format: LOCATION = '[file://] local_file_path'. When you use the local location format, you must set the system variable secure_file_priv to specify an accessible path. For more information, see secure_file_priv.

      • Remote location format: LOCATION = '{oss|cos|S3}://$ACCESS_ID:$ACCESS_KEY@$HOST/remote_file_path'. In this format, $ACCESS_ID, $ACCESS_KEY, and $HOST are required for accessing Alibaba Cloud OSS, Tencent Cloud Object Storage (COS), or Amazon Simple Storage Service (S3).

    • The FORMAT = ( TYPE = 'CSV'... ) option specifies the format of a CSV external file. The parameters are described as follows:

      • TYPE: the type of the external file.

      • LINE_DELIMITER: the line delimiter for the CSV file. The default value is '\n'.

      • FIELD_DELIMITER: the field delimiter for the CSV file. The default value is '\t'.

      • ESCAPE: the escape character for the CSV file, which can be only 1 byte in length. The default value is '\'.

      • FIELD_OPTIONALLY_ENCLOSED_BY: the characters that enclose the field values in the CSV file. By default, this parameter is left empty.

      • ENCODING: the character set encoding used by the file. For more information about all character sets supported in MySQL mode, see Conjuntos de caracteres. If this parameter is not specified, the default value UTF8MB4 takes effect.

      • NULL_IF: the strings to be treated as NULL values. By default, this parameter is left empty.

      • SKIP_HEADER: specifies to skip the file header, and specifies the number of lines to skip.

      • SKIP_BLANK_LINES: specifies whether to skip blank lines. The default value is FALSE, which specifies not to skip blank lines.

      • TRIM_SPACE: specifies whether to remove leading and trailing spaces from fields in the file. The default value is FALSE, which specifies not to remove leading and trailing spaces from fields in the file.

      • EMPTY_FIELD_AS_NULL: specifies whether to treat empty strings as NULL values. The default value is FALSE, which specifies not to treat empty strings as NULL values.

    • The PATTERN option specifies a regular pattern string for filtering files in the LOCATION directory. For each file in the directory specified by LOCATION, if the file path matches the pattern string, the external table accesses the file. Otherwise, the external table skips the file. By default, if this parameter is not specified, all files in the directory specified by LOCATION are accessible. The external table stores the list of files that match the string specified by PATTERN in the system table of the database. During a scan, the external table accesses external files based on this list.

  3. In the left-side navigation pane, view the employee table in the external table directory.

    image

References