MySQL 添加注释的方法

To add comments in MySQL, you can use the following methods:

1. Inline Comments:

  • You can add comments directly in your SQL statements using the -- or # symbols. Anything after these symbols on the same line will be treated as a comment.
  • For example:
    SELECT * FROM table_name WHERE column_name = 'value'; -- This is a comment

2. Multi-line Comments:

  • You can enclose multiple lines of comments within /* and */ symbols.
  • For example:
    This is a multi-line comment
    It can span across multiple lines
    SELECT * FROM table_name;

3. Adding Comments to Tables and Columns:

  • You can add comments to tables and columns using the COMMENT clause when creating or altering the table.
  • For example, when creating a table:
    CREATE TABLE table_name (
        column_name INT COMMENT 'This is a comment'
  • Or when altering a table:
    ALTER TABLE table_name MODIFY column_name INT COMMENT 'This is a comment';

4. Viewing Comments:

  • You can view the comments associated with tables and columns using the SHOW CREATE TABLE statement.
  • For example:
    SHOW CREATE TABLE table_name;

These are some of the methods you can use to add comments in MySQL. Comments can be helpful for documenting your code and providing additional information about your database structure.