Use of table comments
Commenting on each table field helps users better understand the table and each field, facilitating coherent development among developers. Table comments are a favorable supplement to database design documents and a natural feature description.
You can add comments to a table by using two methods:
Add comments to a table when you create the table,
obclient> CREATE TABLE student( id INT PRIMARY KEY AUTO_INCREMENT COMMENT 'Student No.', nameVARCHAR(200) COMMENT 'Name', ageint 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 COMMENT 'Student No.'; obclient> ALTER TABLE student MODIFY COLUMN name COMMENT 'Name'; obclient> ALTER TABLE student MODIFY COLUMN age COMMENT 'Age';We recommend that you use the second method to add comments, that is, use the
ALTERstatement after the table is created. This method facilitates follow-up table maintenance.
Use of comments in SQL statements
OceanBase Database allows you to add comments in general SQL statements by using one of the following three methods:
Start the comment with a number sign (
#) and end it with a line break. The comment text cannot extend to a new line.Start the comment with two hyphens (
--) and end it with a line break. The comment text cannot extend to a new line.Start the comment with a slash and an asterisk (
/*) and end it with an asterisk and a slash (*/). The comment text can span multiple lines.
Note
SQL statements do not support nested comments.
In particular, OceanBase Database can execute statements in /*! */ as SQL statements. If a syntax error occurs in /*! */, OceanBase Database processes it as a comment by default.
Comment format:
/*![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