Updated on 2022-08-17 GMT+08:00

DDL

DDM supports common DDL operations, such as creating databases, creating tables, and modifying table structure, but the implementation method is different from that in common MySQL databases.

DDL Statements that Can Be Executed on a MySQL Client

  • TRUNCATE Syntax
    Example:
    TRUNCATE TABLE t1
    Deletes all data from table t1.
    TRUNCATE TABLE is used to delete all data from a table and has the DROP permission. In logic, TRUNCATE TABLE is similar to the DELETE statement for deleting all data from a table.
  • ALTER TABLE Syntax
    Example:
    ALTER TABLE t2 DROP COLUMN c, DROP COLUMN d;
    Deletes columns c and d fom table t2.
    ALTER is used to add or delete a column, create or drop an index, change the type of an existing column, rename columns or tables, or change the storage engine or comments of a table.
  • DROP INDEX Syntax
    Example:
    DROP INDEX 'PRIMARY' ON t;
    Deletes primary key from table t.
    DROP INDEX is used to delete index index_name from table tbl_name.
  • CREATE INDEX Syntax
    Example:
    CREATE INDEX part_of_name ON customer (name(10));
    Creates an index using the first 10 characters in column name (assuming that there are non-binary character strings in column name).
    CREATE INDEX is used to add an index to an existing table.
  • CREATE, DROP, UPDATE
    Example:
    CREATE DATABASE t shard 100;
    Creates database t that contains 100 shards.
    CREATE DATABASE is used to create a database with a specified name.