mysql怎么查询字段是否存在?[mysql基础教程]
在mysql中可以使用下面的语句判断mysql表中字段是否存在:
select count(*) from information_schema.columns where table_name = '表名' and column_name = '字段名'
示例:
-- ------------------------------ 判断 vrv_paw_rule 表是否存在 thresholdMin 字段,不存在则添加; 存在则修改字段类型
DELIMITER ??
DROP PROCEDURE IF EXISTS schema_change??
CREATE PROCEDURE schema_change()
BEGIN
IF NOT EXISTS (SELECT * FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'vrv_paw_rule' AND column_name = 'thresholdMin') THEN
ALTER TABLE vrv_paw_rule ADD COLUMN thresholdMin BIGINT;
ELSE
ALTER TABLE vrv_paw_rule MODIFY COLUMN thresholdMin BIGINT ;
END IF;
END??
DELIMITER ;
CALL schema_change();
推荐:MySQL教程
以上是 mysql怎么查询字段是否存在?[mysql基础教程] 的全部内容, 来源链接: utcz.com/z/527799.html