在mysql中,如果存在,则在另一列之后添加该列

xdyibdwo  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(365)

怎么可能呢?
我发现它是为了检查列是否存在

(
SELECT 1 FROM Information_schema.columns
WHERE table_schema = 'db' 
AND table_name = 'table' 
AND column_name = 'the other column'
)

并在另一列之后添加该列

ALTER TABLE 'table' ADD 'the column' VARCHAR(14) DEFAULT NULL AFTER 'the other column'
zvms9eto

zvms9eto1#

给出表所在数据库的名称exists:-

ALTER TABLE db.table ADD the_column VARCHAR(14) DEFAULT NULL AFTER the_other_column

它为我工作尝试这个,让我知道它失败的地方

相关问题