0
我在將數據插入到mysql表中時遇到了問題。自動增量跳躍的次數超過插入的行數。按照以下步驟重現該問題。此表格未與其他表格引用。該表格上未創建任何觸發器。沒有刪除查詢在表上執行。自動增量跳躍超過插入的行數?
第1步 - 在mysql中創建一個表。
CREATE TABLE IF NOT EXISTS `tbl_hostel_rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`hostel_id` int(11) NOT NULL,
`room_no` int(11) NOT NULL,
`total_sharing_for_room` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
第2步 - 在表中插入10行並分析結果。這將插入10行並將AUTO_INCREMENT值設置爲11.這也是預期的。
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '101', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '102', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '103', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '104', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '105', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '106', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '107', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '108', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '109', '3');
INSERT INTO `new_db`.`tbl_hostel_rooms` (`id`, `hostel_id`, `room_no`, `total_sharing_for_room`) VALUES (NULL, '1', '110', '3');
第3步 - 使用此查詢插入10多行並分析結果。
INSERT INTO `tbl_hostel_rooms`(`hostel_id`, `room_no`, `total_sharing_for_room`) select `hostel_id`, `room_no`, `total_sharing_for_room` from tbl_hostel_rooms;
這將插入10個行和AUTO_INCREMENT值將被設置爲26。這不期望。現在只插入一行,AUTO_INCREMENT列ID將從27開始。
此問題的解決方案是什麼。
自動增量值用於標識行,但不用於編號行。 – VMai 2014-10-03 10:30:40