mysql 判断字段否存在,如果存在就修改字段
先建一个存储过程,再执行存储过程,然后删掉存储过程。DROP PROCEDURE IF EXISTS proc_tempPro;CREATE PROCEDURE proc_tempPro()BEGINSELECT count(*) into @count FROM INFORMATION_SCHEMA.Columns WHERE table_schema= DATABASE() AND tabl
·
先建一个存储过程,再执行存储过程,然后删掉存储过程。
DROP PROCEDURE IF EXISTS proc_tempPro;
CREATE PROCEDURE proc_tempPro()
BEGIN
SELECT count(*) into @count FROM INFORMATION_SCHEMA.Columns
WHERE table_schema= DATABASE() AND table_name='表名' AND column_name='旧列名';
CREATE PROCEDURE proc_tempPro()
BEGIN
SELECT count(*) into @count FROM INFORMATION_SCHEMA.Columns
WHERE table_schema= DATABASE() AND table_name='表名' AND column_name='旧列名';
if(@count>0) THEN
alter table 表名 change column `旧列名` `新列名` varchar(30) comment '字段说明';
end if;
end;
alter table 表名 change column `旧列名` `新列名` varchar(30) comment '字段说明';
end if;
end;
call proc_tempPro;
DROP PROCEDURE IF EXISTS proc_tempPro;
DROP PROCEDURE IF EXISTS proc_tempPro;
更多推荐
已为社区贡献1条内容
所有评论(0)