使用" SELECT AS"创建表添加其他新列

时间:2014-07-15 15:38:01

标签: mysql

我想基于另一个表创建一个表,但同时也要添加新列。我试着这样做:

CREATE TABLE est_temp AS SELECT establishment_id, uc_l_p INT DEFAULT 0, uc_l_t_p INT DEFAULT 0 FROM establishment;

然而,我在新值uc_l_p和uc_l_t_p附近收到错误。有没有办法在不创建表格的情况下执行此操作,然后对其进行更改以添加新列?

1 个答案:

答案 0 :(得分:5)

尝试

CREATE TABLE est_temp AS 
  SELECT establishment_id, 
         0 as uc_l_p, 
         0 as uc_l_t_p 
  FROM establishment