sqlsever数据库的问题:INSERT 语句与 COLUMN FOREIGN KEY 约束
错误信息:
服务器: 消息 547,级别 16,状态 1,行 1
INSERT 语句与 COLUMN FOREIGN KEY 约束 'FK__SC__Cno__263B8EAF' 冲突。该冲突发生于数据库 'master',表 'Course', column 'Cno'。
语句已终止。
服务器: 消息 547,级别 16,状态 1,行 1
INSERT 语句与 COLUMN FOREIGN KEY 约束 'FK__SC__Cno__263B8EAF' 冲突。该冲突发生于数据库 'master',表 'Course', column 'Cno'。
语句已终止。
sql语句:
CREATE TABLE Student数据库 sql
(Sno CHAR(9) PRIMARY KEY,
Sname CHAR(20) UNIQUE,
Ssex CHAR(2),
Sage SMALLINT,
Sdept CHAR(20)
);
CREATE TABLE Course
(Cno CHAR(4) PRIMARY KEY,
Cname CHAR(40),
Cpno CHAR(4),
Ccredit SMALLINT,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
CREATE TABLE SC
(Sno CHAR(9),
Cno CHAR(4),
Grade SMALLINT,
PRIMARY KEY (Sno,Cno),
FOREIGN KEY (Sno) REFERENCES Student(Sno),
FOREIGN KEY (Cno) REFERENCES Course(Cno)
);
SELECT *
FROM Student;
INSERT
INTO Student(Sno,Sname,Ssex,Sdept,Sage)
VALUES('200215128','陈冬','男','IS',18);
INSERT
INTO Student
VALUES('200215126','张成民','男',18,'CS');
INSERT
INTO SC(Sno,Cno)
VALUES('200215128','1');
INSERT
INTO SC
VALUES('200215126','1',NULL);
CREATE TABLE Student
(Sno CHAR(9) PRIMARY KEY,
Sname CHAR(20) UNIQUE,
Ssex CHAR(2),
Sage SMALLINT,
Sdept CHAR(20)
);
CREATE TABLE Course
(Cno CHAR(4) PRIMARY KEY,
Cname CHAR(40),
Cpno CHAR(4),
Ccredit SMALLINT,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
CREATE TABLE SC
(Sno CHAR(9),
Cno CHAR(4),
Grade SMALLINT,
PRIMARY KEY (Sno,Cno),
FOREIGN KEY (Sno) REFERENCES Student(Sno),
FOREIGN KEY (Cno) REFERENCES Course(Cno)
);
INSERT INTO Student(Sno,Sname,Ssex,Sdept,Sage)
VALUES('200215128','陈冬','男','IS',18);
INSERT INTO Student
VALUES('200215126','张成民','男',18,'CS');
-- 插入Cno为1的记录.
insert into Course(Cno,Cname,Cpno,Ccredit)
select '1','Cno1','1',10
INSERT INTO SC(Sno,Cno)
VALUES('200215128','1');
INSERT INTO SC
VALUES('200215126','1',NULL);