Insert Into, Insert Ignore, Replace Into, Insert & Update

CREATE TABLE `test` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  `gold` int(11) DEFAULT '0',
  PRIMARY KEY (`uid`),
  UNIQUE KEY `ix_name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

INSERT INTO :   插入; 已存在, 插入失败

INSERT IGNORE : 插入; 已存在, 忽略插入

REPLACE INTO :  插入; 已存在, 删除后插入

INSERT UPDATE : 插入; 已存在, 更新

 



 

 

 

 

猜你喜欢

转载自laughing-ing.iteye.com/blog/2068806