mysql insert 返回值
2012-11-14 11:48
127 查看
先上代码:
结论:当表的主键字段不是自增的时候,添加一条数据返回的最后插入字段的id的值就是0,但并不表示其插入错误或没有插入成功
mysql> insert into hello(id, age) value (12,8); Query OK, 1 row affected (0.00 sec) mysql> select last_insert_id(); +------------------+ | last_insert_id() | +------------------+ | 0 | +------------------+ 1 row in set (0.00 sec) mysql> desc hello; +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | id | int(11) | NO | PRI | NULL | | | age | int(11) | YES | | NULL | | +-------+---------+------+-----+---------+-------+ 2 rows in set (0.01 sec) mysql> select * from hello; +----+------+ | id | age | +----+------+ | 1 | NULL | | 2 | NULL | | 5 | 0 | | 6 | NULL | | 9 | 1 | | 10 | 2 | | 11 | 8 | | 12 | 8 | +----+------+ 8 rows in set (0.00 sec)
结论:当表的主键字段不是自增的时候,添加一条数据返回的最后插入字段的id的值就是0,但并不表示其插入错误或没有插入成功
相关文章推荐
- asp.net调用mysql 存储过程 带 out 返回值,返回刚插入数据库中的自增的ID,LAST_INSERT_ID() 的使用
- 在ibatis和mysql环境下使用insert如何获取返回值
- asp.net调用mysql 存储过程 带 out 返回值,返回刚插入数据库中的自增的ID,LAST_INSERT_ID() 的使用
- mysql insert操作
- MySQL中的insert ignore into, replace into等的一些用法总结
- MySQL 语句级避免重复插入—— Insert Select Not Exist
- MySQL因大事务导致的Insert慢实例分析
- 使用batch insert解决MySQL的insert吞吐量问题 - billy鹏
- 教你如何调整Mysql中insert、update、delete的顺序来以提高效率
- MySQL 当记录不存在时insert,当记录存在时update
- MySQL--操作简记(create创建操纵表、insert插入、update更新、delete删除数据)
- mysql 之insert
- MySQL中INSERT的一般用法
- 对mysql中last_insert_id()的新理解
- MySQL中insert语句的使用与优化教程
- mysql 使用 insert ignore into和unique实现不插入重复数据功能
- 转载:mysql 操作总结 INSERT和REPLACE
- Mysql只导单行的INSERT语句
- MYSQL INSERT语句
- Mysql的INSERT INTO SELECT与SELECT INTO FROM