MySQL Tutorial/Introduction/comments — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 09:49, 26 мая 2010

From a # character to the end of the line

mysql>
mysql> SELECT 1+1;     # This comment continues to the end of line
+-----+
| 1+1 |
+-----+
|   2 |
+-----+
1 row in set (0.00 sec)
mysql>


From a "--" sequence to the end of the line

mysql>
mysql> SELECT 1+1;     -- This comment continues to the end of line
+-----+
| 1+1 |
+-----+
|   2 |
+-----+
1 row in set (0.00 sec)


/*! MySQL-specific code */

MySQL Server parses and executes the code within the comment.

Other SQL servers will ignore the extensions.

If you add a version number after the ! character, the syntax within the comment is executed only if the MySQL version is greater than or equal to the specified version number.



mysql>
mysql>
mysql> CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
Query OK, 0 rows affected (0.02 sec)
mysql>
mysql> desc t;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| a     | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql>
mysql>
mysql> drop table t;
Query OK, 0 rows affected (0.00 sec)
mysql>


This syntax allows a comment to extend over multiple lines not be on the same line.

mysql>
mysql>
mysql> SELECT 1 /* this is an in-line comment */ + 1;
+---------+
| 1   + 1 |
+---------+
|       2 |
+---------+
1 row in set (0.00 sec)
mysql> SELECT 1+
    -> /*
   /*> this is a
   /*> multiple-line comment
   /*> */
    -> 1;
+-------+
| 1+
1 |
+-------+
|     2 |
+-------+
1 row in set (0.00 sec)
mysql>