在mysql中可以使用下面的语句判断mysql表中字段是否存在:selectcount(*)frominformation_schema.columnswheretable_name='表名'andcolumn_name='字段名'
示例:------------------------------
--判断vrv_paw_rule表是否存在thresholdMin字段,不存在则添加;存在则修改字段类型
DELIMITER??
DROPPROCEDUREIFEXISTSschema_change??
CREATEPROCEDUREschema_change()
BEGIN
IFNOTEXISTS(SELECT*FROMinformation_schema.columnsWHEREtable_schema=DATABASE()ANDtable_name='vrv_paw_rule'ANDcolumn_name='thresholdMin')THEN
ALTERTABLEvrv_paw_ruleADDCOLUMNthresholdMinBIGINT;
ELSE
ALTERTABLEvrv_paw_ruleMODIFYCOLUMNthresholdMinBIGINT;
ENDIF;
END??
DELIMITER;
CALLschema_change();