CREATE...SELECT 问题
如果用CREATE...SELECT方法创建tdb_goods_cates表,如下,会出现错误
mysql> CREATE TABLE tdb_goods_cates(
cate_id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
cate_name VARCHAR(40) NOT NULL
)SELECT goods_cate FROM tdb_goods GROUP BY goods_cate;
ERROR 1364 (HY000): Field 'cate_name' doesn't have a default value
但是如果把上面的cate_name 改为goods_cate 如下:
mysql> CREATE TABLE tdb_goods_cates(
-> cate_id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
-> goods_cate VARCHAR(40) NOT NULL
-> )
-> SELECT goods_cate from tdb_goods group by goods_cate;
Query OK, 7 rows affected (0.02 sec)
Records: 7 Duplicates: 0 Warnings: 0
成功创建表。
难道用CREATE..SELECT 方法创建表的时候,字段要和原表相同吗??