Custom comment using CREATE TABLE .... SELECT seems not possible.
Documentation on CREATE TABLE ... SELECT does only specify that the parent comments are retained. It did not mention anything if an in line new comment is defined using create ... select syntax, what the behaviour is.
Retrained attributes are NULL (or NOT NULL) and, for those columns that have them, CHARACTER SET, COLLATION, COMMENT, and the DEFAULT clause
Following observations say that that the new custom comment being tried on new column is ignored.
And if you still want to re-define your own comment, you have to use alter table command to add on the newly created table column.
Example:
mysql> create table tbl_so_q23798048_1( i int not null comment 'parent comment' ); Query OK, 0 rows affected (0.41 sec) mysql> select table_name, column_name, column_comment -> from information_schema.columns -> where table_schema='so' and length(column_comment)>0; +--------------------+-------------+-----------------+ | table_name | column_name | column_comment | +--------------------+-------------+-----------------+ | tbl_so_q23798048_1 | i | parent comment | +--------------------+-------------+-----------------+ 1 row in set (0.01 sec)
Now, try to create a table based on the previously created table but with custom comment.
mysql> create table tbl_so_q23798048_2( i int comment 'custom comment' ) -> as select i from tbl_so_q23798048_1; Query OK, 0 rows affected (0.42 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select table_name, column_name, column_comment -> from information_schema.columns -> where table_schema='so' and length(column_comment)>0; +--------------------+-------------+-----------------+ | table_name | column_name | column_comment | +--------------------+-------------+-----------------+ | tbl_so_q23798048_1 | i | parent comment | | tbl_so_q23798048_2 | i | parent comment | +--------------------+-------------+-----------------+ 2 rows in set (0.01 sec)
You can clearly see that custom comment is ignored.
Now, try with no custom comment on the new table's column.
mysql> create table tbl_so_q23798048_3( i int ) -> as select i from tbl_so_q23798048_1; Query OK, 0 rows affected (0.35 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select table_name, column_name, column_comment -> from information_schema.columns -> where table_schema='so' and length(column_comment)>0; +--------------------+-------------+-----------------+ | table_name | column_name | column_comment | +--------------------+-------------+-----------------+ | tbl_so_q23798048_1 | i | parent comment | | tbl_so_q23798048_2 | i | parent comment | | tbl_so_q23798048_3 | i | parent comment | +--------------------+-------------+-----------------+ 3 rows in set (0.01 sec)
You can see that parent comment is retained. Now, you can alter the new table's column to add custom comment.
mysql> alter table tbl_so_q23798048_3 -> modify column i int comment 'custom comment'; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select table_name, column_name, column_comment -> from information_schema.columns -> where table_schema='so' and length(column_comment)>0; +--------------------+-------------+-----------------+ | table_name | column_name | column_comment | +--------------------+-------------+-----------------+ | tbl_so_q23798048_1 | i | parent comment | | tbl_so_q23798048_2 | i | parent comment | | tbl_so_q23798048_3 | i | custom comment | +--------------------+-------------+-----------------+ 3 rows in set (0.01 sec)
And, you can't define new comment though the table column being selected does not have a comment on it.
mysql> create table tbl_so_q23798048_4( i int ); Query OK, 0 rows affected (0.68 sec) mysql> create table tbl_so_q23798048_5( i int comment 'new comment' ) -> as select i from tbl_so_q23798048_4; Query OK, 0 rows affected (0.05 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select table_name, column_name, column_comment -> from information_schema.columns -> where table_schema='so' and length(column_comment)>0 -> and table_name in ( 'tbl_so_q23798048_4', 'tbl_so_q23798048_5' ); Empty set (0.01 sec)
SELECTstatement have to do with your table creation? Why is it important / what significance does it have?SELECTstatement, it adds to insert the records that match the condition from other table.