Table comments
Adding comments to each field of a table helps to better understand the table and the purpose of each field through the create table statement. It promotes collaborative development among developers and serves as a valuable supplement to the database design document by providing natural functional instructions.
You can add comments to a table in two ways:
Add comments to a table when you create the table.
obclient> CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'Student No.', name VARCHAR(200) COMMENT 'Name', age INT COMMENT 'Age') COMMENT='Student information';After you create the table, use the
ALTERstatement to add comments.obclient> CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT , name VARCHAR(200) , age INT); obclient> ALTER TABLE student COMMENT 'Student information'; obclient> ALTER TABLE student MODIFY COLUMN id INT COMMENT 'Student No.'; obclient> ALTER TABLE student MODIFY COLUMN name VARCHAR(200) COMMENT 'Name'; obclient> ALTER TABLE student MODIFY COLUMN age INT COMMENT 'Age';We recommend the second method, that is, use the
ALTERstatement after the table is created. This facilitates subsequent table maintenance.
Comments in SQL statements
OceanBase Database allows you to add comments in general SQL statements by using one of the following three methods:
From
#to the end of the line, you can comment a single line.From
--to the end of the line, you can comment a single line.From
/*to*/, you can comment multiple lines.Note
SQL statements do not support nested comments.
In particular, OceanBase Database can execute statements inside /*!*/ as SQL statements. If a syntax error occurs in /*!*/, the database treats it as a comment by default.
The comment format is as follows:
/*![Consecutive numeric characters representing the version]<Space><Any SQL statement>*/
Example:
Create eight hash partitions for table
t1.obclient> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT) /*!50100 PARTITION BY HASH(c1) PARTITIONS 8*/; Query OK, 0 rows affectedYou can use
ENABLE KEYSto update non-unique indexes. During batch insertion, you can useDISABLE KEYSto postpone the update until all indexes are inserted.obclient> /*!ALTER TABLE t1 DISABLE KEYS */; Query OK, 0 rows affected obclient> /*!ALTER TABLE t1 ENABLE KEYS */; Query OK, 0 rows affectedThe
DROP IF EXISTSsyntax of PL is supported.obclient> /*!50003 DROP PROCEDURE IF EXISTS */; Query OK, 0 rows affected