我在围棋writen一个简单的代码在MySQL DATABSE插入id不按照顺序,我的表结构是:mysql的自动递增时使用预处理语句
id PK, AUTO_INCREMENT
name varchar(100)
email varchar(100), UNIQUE
和我去的代码是:
stmt, err := c.mysql.Prepare("INSERT mytable SET name = ?, email = ?")
checkError(err)
res, err := stmt.Exec("My Name", "[email protected]")
checkError(err)
lastId, err := res.LastInsertId()
checkError(err)
当电子邮件未在登记台上登记时,插入成功。
但是,当这封邮件注册的银行返回我唯一键的错误,这是正确的
当我插入获得的唯一密钥错误之后的记录错误发生时,新的插入成功建立,但银行ID是不正确的顺序,例如
insert 'My name', '[email protected]' -> id returned 1
insert 'My name', '[email protected]' -> id returned 2
insert 'My name', '[email protected]' -> Unique key error returned
insert 'My name', '[email protected]' -> id returned 4
insert 'My name', '[email protected]' -> Unique key error returned
insert 'My name', '[email protected]' -> Unique key error returned
insert 'My name', '[email protected]' -> id returned 7
这是正确的行为。为什么序列中的差距是一个问题? –