** 我想將 date_col 添加到 new_table_name,我正在嘗試下面的查詢但收到錯誤 **
CREATE TABLE IF NOT EXISTS new_table_name AS
SELECT A.employee AS employee_name,
A.loc AS location,
'America' country,
date_col TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
FROM existing_table_name;
uj5u.com熱心網友回復:
CREATE TABLE ... AS SELECT ...不是為了向新表中添加新行為。向列添加默認值等更改應在單獨的ALTER陳述句中進行。因此,使用這種方法:
CREATE TABLE IF NOT EXISTS new_table_name AS
SELECT employee,
location,
'America',
date_col,
FROM existing_table_name;
ALTER TABLE new_table_name
MODIFY COLUMN date_col TIMESTAMP NOT NULL
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
如果您打算將這些別名作為更改列名的說明,那么您也需要針對這些別名的ALTER陳述句:
ALTER TABLE new_table_name
RENAME COLUMN employee TO employee_name;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/504987.html
