MySQL, Check if a column exists in a table with SQL
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I thought something like IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='prefix_topic' AND column_name='topic_last_update') BEGIN ALTER TABLE `prefix_topic` ADD `topic_last_update` DATETIME NOT NULL; UPDATE `prefix_topic` SET `topic_last_update` = `topic_date_add`; END; would work, but it fails badly. Is there a way? 回答1: @julio Thanks for the SQL example. I tried the query and I think it needs a small alteration to get it working properly. SELECT * FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'db_name' AND