0
我是從一個表students
選擇數據並將其插入到所述tests
表等插入忽略未能防止重複插入
CREATE TABLE tests(
`student_id` int NOT NULL,
`student_iden_number` varchar(255) NOT NULL DEFAULT '000000',
`student_names` varchar(255) NOT NULL DEFAULT 'jane doe'
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
我使用這個代碼
insert ignore into tests (student_id,student_iden_number,student_names) select student_id,student_iden_number,student_names from students;
然而,如果我運行插入忽略代碼兩次,插入重複記錄。這是我的students
表
CREATE TABLE `students` (
`student_id` INT NOT NULL AUTO_INCREMENT,
`student_iden_number` varchar(255) NOT NULL DEFAULT '000000',
`student_names` varchar(255) NOT NULL DEFAULT 'jane doe',
`student_gender` ENUM('female', 'male') DEFAULT 'female',
`student_guardian_names` varchar(255) NOT NULL DEFAULT 'the guardian',
`student_guardian_telephone` varchar(255) NOT NULL DEFAULT '0000000',
`student_date_of_birth` DATE DEFAULT '00-00-0000',
`student_date_entered` DATE DEFAULT '00-00-0000',
`student_date_left` DATE DEFAULT '00-00-0000',
`student_current_status` ENUM('in-session', 'suspended', 'expelled-for-good', 'at-home-sick', 'cleared' ,'other') DEFAULT 'other',
`student_profile` varchar(255) DEFAULT 'lorem ipsum',
`student_picture` varchar(255) NOT NULL DEFAULT 'placeholder.png',
`student_has_a_medical_condition` ENUM('no', 'yes') DEFAULT 'no',
`student_name_of_condition` varchar(255) NOT NULL DEFAULT 'none',
`student_current_home_address` varchar(255) NOT NULL DEFAULT 'home address',
`student_current_home_latitude` varchar(255) NOT NULL DEFAULT '0000-00-000',
PRIMARY KEY (`student_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
爲什麼插入重複數據而不是忽略它?