苗火 Nicholas
[MySQL]insert和update的一些注意点
2015-12-18 萧
insert:对于已存在的主键出错;

update:如果指定条件where,数据全部更新

update:更新全部数据的时候如果造成主键重复同样报错,没有主键的表就不会存在这个数据。




下面是一个测试用例:



CREATE TABLE `test` (
`name` varchar(11) NOT NULL DEFAULT '',
`passwd` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

select * from test;

insert into test set name="aaa",passwd="bbbb";

update test set name="baa",passwd="ccc";

update test set name="aaa2",passwd="ccc" where name="aaa";

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容