【发布时间】:2018-05-29 08:13:14
【问题描述】:
我在 SQL 中创建了下表。然后输入数据。然后我添加了另一列(电子邮件)。接下来我需要将数据插入到电子邮件列。但是有一个错误。
CREATE TABLE Library_books (
ISBN VARCHAR(15),
Book_name VARCHAR(20),
subject TEXT(12),
student_id VARCHAR(4),
borrow_date DATE,
PRIMARY KEY (ISBN),
FOREIGN KEY (student_id)
REFERENCES student (SID)
);
INSERT INTO Library_books VALUES ('1-22-5567-4' ,'Vectors' ,'Mathematics', 'S021', '2015-04-23'),
('978-14840-0' ,'The C Programming ' ,'Computer' , 'S005', '2016-03-01'),
('567-2-13-145-3' ,'Code complete' ,'Computer' , 'S005', '2016-06-04'),
('345-6-7889-5' ,'How to solve it' ,'Mathematics', 'S090', '2016-08-12'),
('34-22-34556-4' ,'Real Analysis' ,'Mathematics', 'S021', '2016-10-22'),
('3-445-7-8' ,'Python' ,'Computer' , 'S021', '2016-09-11');
INSERT INTO student (email) VALUES ('Bob@gmail.com'),
('John@gmail.com'),
('Albert@gmail.com'),
('Sam@gmail.com'),
('Tom@gmail.com'),
('Liz@gmail.com') ;
CREATE table student (SID varchar(4) NOT NULL,
student_name varchar(10) NOT NULL,
address varchar(12) NOT NULL,
age int NOT NULL,
telephoneNo varchar(12) NOT NULL,
primary key (SID));
结果:
错误 1062 (23000): 键 'PRIMARY' 的重复条目 ''
【问题讨论】:
-
你遇到了什么错误?
-
我认为你不应该使用 ISBN 作为主键。它留在数据库中,当你尝试插入相同的数据时,就会出现这个错误。
-
@SureshPrajapati "ERROR 1062 (23000): Duplicate entry '' for key 'PRIMARY'"
-
能否请您包括学生表的架构,似乎错误与电子邮件的插入有关。目前还不清楚错误与哪个语句有关。
-
@deHaar 谢谢!,您有什么建议吗?
标签: mysql sql sql-server database sql-insert