0

嘿,伙计们,我已经通过论坛搜索了答案,但无济于事,所以我正在使用 MySql,我正在尝试为某些表插入语句,但它们没有进入表中,我收到类似“Msg”的错误8152,级别 16,状态 14,第 1 行字符串或二进制数据将被截断。语句已终止。这些是我遇到问题的陈述。`INSERT INTO Course VALUES

INSERT INTO Course VALUES (12345, 'DatabaseManagement', '2015-2-1', '2014-5-9');
INSERT INTO Course VALUES (12346, 'Calculus', '2015-1-12', '2015-5-9');
INSERT INTO Course VALUES (12347, 'Biology', '2015-1-3', '2015-5-9');
INSERT INTO Course VALUES (12348, 'Chemistry', '2015-1-2', '2015-5-9');

INSERT INTO Grade VALUES (10, 12345, 012, 'A');
INSERT INTO Grade VALUES (11, 12346, 013, 'B');
INSERT INTO Grade VALUES (12, 12347, 014, 'C');
INSERT INTO Grade VALUES (13, 12348, 015, 'D');
INSERT INTO Grade VALUES (14, 12345, 016, 'B');

INSERT INTO Student VALUES (54321, 'Rachel', 'Cotterel', '2013-4-15', '2016-3-4');
INSERT INTO Student VALUES (54320, 'John', 'Smith', '2012-1-23', NULL);
INSERT INTO Student VALUES (54319, 'Johny', 'Depp', '2010-5-12', '2012-10-10');
INSERT INTO Student VALUES (54318, 'Orlando', 'Bloom', '2014-6-24', NULL);
INSERT INTO Student VALUES (54317, 'Linda', 'Jacob', '2015-4-4', '2019-8-6');
4

4 回答 4

0

我没有收到任何插入课程语句的错误。我收到了 INSERT INTO Grade 语句的错误。这是因为 Student 表中没有 StudentID 012,013 等可用的参考。你正试图将它们添加到成绩表中。

于 2015-02-07T05:38:26.550 回答
0

这些是字段类型:

CREATE TABLE Course
(
CourseID int,
Description varchar(20) NOT NULL,
StartDate DATE NOT NULL,
EndDate DATE NOT NULL,
CONSTRAINT [PK_CourseID] PRIMARY KEY (CourseID)
);  

CREATE TABLE Grade
(
GradeID integer(10) NOT NULL,
CourseID integer(10) NOT NULL,
StudentID integer(10) NOT NULL,
Grade varchar (10) NULL,
CONSTRAINT [PK_GradeID] PRIMARY KEY (GradeID),
CONSTRAINT [FK_CourseID] FOREIGN KEY (CourseID) REFERENCES Course(CourseID),
CONSTRAINT [FK_StudentID] FOREIGN KEY (StudentID) REFERENCES Student(StudentID)
);

CREATE TABLE Student
(
StudentID integer(10) NOT NULL,
FirstName varchar(45) NOT NULL,
LastName varchar(45) NOT NULL,
RegistrationDate varchar (45) NOT NULL,
GraduationDate DATE NULL,
CONSTRAINT [PK_StudentlID] PRIMARY KEY (StudentID)
);
于 2015-02-07T00:00:51.873 回答
0

字符串或二进制数据将被截断您收到此消息的原因应该是您试图将一些值插入到您没有分配足够大小来保存该值的某个字段。你能发送你得到的确切错误信息吗?

我自己尝试做。但是我得到的错误是从你插入查询到 Grade 表外键失败,它引用了 Student 表,因为你试图插入 Student 表中不存在的 Student_ID

于 2015-02-07T03:35:32.577 回答
0

尝试使用这个:

INSERT INTO table1 (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
于 2015-02-06T23:19:57.737 回答