auto_increment usage in composite key

放肆的年华 提交于 2019-11-29 11:57:05

This is what happens with a composite primary key that incorporates a auto_increment. Recreate the primary key so that it's purely your auto_increment field (empId) then create a unique index on companyId and empId

EDIT

Note that this only applies to MyISAM and BDB tables. If you used InnoDB for your tables, then it would also work as you wanted

If you do not want empId to reset then just reverse the order of primary definition

primary key(companyId,empId)

note that composite key order matters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!