MySQL:SQL注释


#MySQL 笔记


方式1:

-- :注意右侧有一个空格。

示例:

-- 这张表是测试用的
create table test_table (
    num int  -- 这是注释
) engine = InnoDB character set = utf8mb4;

在上面的创建语句中,如果--右侧没空格,会报语法错误。

为什么右侧要有空格,因为-也是减号,要做区分。

# 下面这个不是注释,是减去-1的意思
mysql> select 2--1
+------+
| 2--1 |
+------+
| 3    |
+------+
1 row in set

# 下面这个是注释
mysql> select 2-- 1
+---+
| 2 |
+---+
| 2 |
+---+
1 row in set

# 下面这个不是注释,是减去-1的意思
mysql> select 2 --1
+-------+
| 2 --1 |
+-------+
| 3     |
+-------+
1 row in set

方式2

#

示例:

# 这张表是测试用的
create table test_table (
    num int  # 这是注释
) engine = InnoDB character set = utf8mb4;

方式3

/* */ :多行注释

示例:

/*
这张表是测试用的
*/
create table test_table (
    num int  /*这是注释*/
) engine = InnoDB character set = utf8mb4;


( 本文完 )