Table comments
Adding comments to each field of a table helps to better understand the table and its fields through the create table statement. It also promotes collaborative development among developers and serves as a valuable supplement to the database design document by providing natural functional instructions.
Note
When you use COMMENT to add comments to columns, note the following length limits based on different database modes:
- In MySQL mode, the maximum length of the comment cannot exceed 1024 characters.
- In Oracle mode, the maximum length of the comment cannot exceed 4000 bytes.
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.', 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 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.
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.
The comment format is as follows:
/*![Consecutive numeric characters representing the version]<Space><Any SQL statement>*/
Here are some examples:
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