在数据库DBNAME的表TableA中增加字段newcol,如果已有此字段则不增加,我写成这样if not exists(
select 1 from information_schema.columns where table_schema='DBNAME' and table_name='TableA' and column_name='newcol'
)
alter table DBNAME.TableA add column newcol varchar(10) default null;貌似不对,请问应该怎么写。
select 1 from information_schema.columns where table_schema='DBNAME' and table_name='TableA' and column_name='newcol'
)
alter table DBNAME.TableA add column newcol varchar(10) default null;貌似不对,请问应该怎么写。
解决方案 »
- Excel中vba代码用odbc连接mysql数据库
- replace的原理是?它一定比update的效率高吗?
- 我这种情况下,用动态sql好呢?还是汇总全部数据,然后删除无用记录好?
- 一个触发器问题 MYSQL
- 跪求mysql多表联查问题(在线等)
- 求教mysql从文本部分读取
- 有没有高手知道MySQL的AES密码是如何生成的?
- 在W98的单机上怎么连接MySQL数据库呀?
- mysql主从复制:数据中的字符很大,数据量也大,所有要用slave_exec_mod,具体怎么做,别随便给我一些资料,我要的是具体的对主从服务器的操作
- 关于mysql主从复制问题,我为啥我主库事务,从库都没反应配置都对的
- mysql怎么样备份到到指定文件夹中? 解决即给分
- 创建触发器函数
select 1 from information_schema.columns where table_schema='DBNAME' and table_name='TableA' and column_name='newcol'
) then
alter table DBNAME.TableA add column newcol varchar(10) default null;
end if
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `zz`.`zjzd`()
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
if not exists(
select 1 from information_schema.columns where table_schema='ZZ' and table_name='AA' and column_name='newcol'
) then
alter table ZZ.AA add column newcol varchar(10) default null;
end if;
END$$DELIMITER ;
调试通过