MYSQL 增加字段不报错,插入数据不报错处理
INSERT INTO `InApp_WebSort` (`sort_id`,`sort_name`,`parentid`,`ifdisplay`,`sort_href`,`sort_icon_href`,`cate`,`SortNum`,`cate_name`,`encate_name`,`grade`,`has_child`)VALUES ('92', 'vipset', '89', '1', null, 'admin/butler/vipset', '', '0', 'vip优惠设定', 'vipset', '2', '0') ON DUPLICATE KEY UPDATE sort_name = "vipset";
重点在
ON DUPLICATE KEY UPDATE sort_name = "vipset"
DELIMITER $$ DROP PROCEDURE IF EXISTS `ALTER_Field`$$ CREATE PROCEDURE `ALTER_Field`() BEGIN IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'InApp_AdminMember' AND column_name = 'quota') = FALSE THEN ALTER TABLE `InApp_AdminMember` ADD `quota` int(10) NOT NULL DEFAULT '0' COMMENT '限额'; END IF; IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'InApp_AdminMember' AND column_name = 'point') = FALSE THEN ALTER TABLE `InApp_AdminMember` ADD `point` int(10) NOT NULL DEFAULT '0' COMMENT '已充金额'; END IF; IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'InApp_WalletPoint' AND column_name = 'giving_money') = FALSE THEN ALTER TABLE `InApp_WalletPoint` ADD `giving_money` int(10) NOT NULL DEFAULT '0' COMMENT '赠幣數'; END IF; IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'InApp_WalletPoint' AND column_name = 'consume_money') = FALSE THEN ALTER TABLE `InApp_WalletPoint` ADD `consume_money` int(10) NOT NULL DEFAULT '0' COMMENT '赠币消耗'; END IF; END$$ DELIMITER ; CALL ALTER_Field(); DROP PROCEDURE IF EXISTS `ALTER_Field`;
DELIMITER $$ DROP PROCEDURE IF EXISTS `ALTER_Field`$$ CREATE PROCEDURE `ALTER_Field`() BEGIN IF EXISTS (SELECT * FROM information_schema.columns WHERE table_name = 'Dog_Photo' AND column_name = 'gif') = FALSE THEN ALTER TABLE `Dog_Photo` add gif varchar(200) NOT NULL; END IF; END$$ DELIMITER ; CALL ALTER_Field(); DROP PROCEDURE IF EXISTS `ALTER_Field`;