create database university;
use university;
create table student(
sno int,sname char(10),year int,dept char(20), primary key(sno)
);
create table course(
cno char(20), cname char(20),credit int,dept char(20), prname char(10), primary key(cno)
);
create table enroll(
sno int, cno char(20), grade char(10),midterm int, final int, foreign key(cno) references course(cno), foreign key(sno) references student(sno)
);
insert into student values
(100,'나수영',4,'컴퓨터');
insert into student values
(200,'이찬수',3,'전기');
insert into student values
(300,'정기태',1,'컴퓨터');
insert into student values
(400,'송병길',4,'컴퓨터');
insert into student values
(500,'박종화',2,'산공');
insert into course values
('C123','프로그래밍',3,'컴퓨터','김성국');
insert into course values
('C312','자료구조',3,'컴퓨터','황수관');
insert into course values
('C324','화일구조',3,'컴퓨터','이규찬');
insert into course values
('C413','데이타베이스',3,'컴퓨터','이일로');
insert into course values
('E412','반도체',3,'전자','홍봉진');
insert into enroll values - 오류시작부분
(100,'C412','A',90,95);
insert into enroll values
(100,'E412','A',95,95);
insert into enroll values
(200,'C123','B',85,80);
insert into enroll values
(300,'C312','A',90,95);
insert into enroll values
(300,'C324','C',75,75);
insert into enroll values
(300,'C413','A',95,90);
insert into enroll values
(400,'C312','A',90,95);
insert into enroll values
(400,'C324','A',95,90);
insert into enroll values
(400,'C413','B',80,85);
insert into enroll values
(400,'E412','C',65,75);
insert into enroll values
(500,'C312','B',85,80);
Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`university`.`enroll`, CONSTRAINT `enroll_ibfk_1` FOREIGN KEY (`cno`) REFERENCES `course` (`cno`))
ㅎ
외래키 완련해서 서로 안맞는다는것 같은데...
진짜 이유를 모르겠습니다..
인터넷에 구글링 하고 암만그래도 해결이 안됩니다..
게시판과 카테고리에 맞는지 안맞는지도 모른체 물어보기만 해서 죄송합니다.
정말 모르겠는데 물어볼곳도 없어서 적어봅니다..
Comment 1
-
건우아빠
2017.04.18 09:44
C412 가 없는데요.