17. MySQL5.7 新機能:
GENERATED COLUMN
日本語で「生成列」とも。
mysql> CREATE TABLE gentest (a int, b int, c int GENERATED ALWAYS AS (a+b));
mysql> INSERT INTO gentest (a,b) values (3,5),(2,9);
mysql> SELECT * FROM gentest;
+------+------+------+
| a | b | c |
+------+------+------+
| 3 | 5 | 8 |
| 2 | 9 | 11 |
+------+------+------+
mysql> CREATE TABLE gentest2 (a int, b int,
c int GENERATED ALWAYS AS ((a+b)*rand()));
ERROR 3102 (HY000): Expression of generated column 'c' contains a disallowed
function.
19. 例:
×
SELECT mycode, name, count(*)
FROM tbl1
GROUP BY mycode;
SQL_MODE: ONLY_FULL_GROUP_BY
MySQLの(SQL学習者にとって)
イケてなかったところ
20. 例:
×
SELECT mycode, name, count(*)
FROM tbl1 GROUP BY mycode;
○
SELECT mycode, name, count(*)
FROM tbl1 GROUP BY mycode, name;
SQL_MODE: ONLY_FULL_GROUP_BY