Comments within SQL statements and database objects are specified in different ways.
Comments within 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 1: Create
8eight hash partitions for tablet1.obclient> CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT) /*!50100 PARTITION BY HASH(c1) PARTITIONS 8*/; Query OK, 0 rows affectedExample 2: 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 affectedExample 3: The
DROP IF EXISTSsyntax of PL is supported.obclient> /*!50003 DROP PROCEDURE IF EXISTS */; Query OK, 0 rows affected
Comments for database objects
You can use a COMMENT clause in a DDL statement to specify comments for a database object. Sample code:
obclient> CREATE TABLE tbl1(pk INT PRIMARY KEY COMMENT 'primary key');
Query OK, 0 rows affected