本题目要求编写SQL语句, 检索出没有选修'C语言'课程的学生记录,输出结果集按照学号升序排序。 要求使用not exist语句实现。 表结构: 请在这里写定义表结构的SQL语句。例如: CREATE TABLE `stu` ( `sno` char(4) NOT NULL, `sname` char(8) NOT NULL, `sex` tinyint(1) DEFAULT NULL, `mno` char(2) DEFAULT NULL, `birdate` datetime DEFAULT NULL, `memo` text, PRIMARY KEY (`sno`) ); CREATE TABLE `cou` ( `cno` char(4) NOT NULL, `cname` varchar(30) NOT NULL, `credit` smallint(6) DEFAULT NULL, `ptime` char(5) DEFAULT NULL, `teacher` char(10) DEFAULT NULL, PRIMARY KEY (`cno`) ) ; CREATE TABLE `sc` ( `sno` char(4) NOT NULL, `cno` char(4) NOT NULL, `grade` decimal(6,1) DEFAULT NULL, PRIMARY KEY (`sno`,`cno`), CONSTRAINT `fk_sc_cno` FOREIGN KEY (`cno`) REFERENCES `cou` (`CNO`), CONSTRAINT `fk_sc_sno` FOREIGN KEY (`sno`) REFERENCES `stu` (`sno`) );
时间: 2023-07-24 09:47:30 浏览: 204
创建学生表的sql语句
CREATE TABLE `stu` (
`sno` char(4) NOT NULL,
`sname` char(8) NOT NULL,
`sex` tinyint(1) DEFAULT NULL,
`mno` char(2) DEFAULT NULL,
`birdate` datetime DEFAULT NULL,
`memo` text,
PRIMARY KEY (`sno`)
);
CREATE TABLE `cou` (
`cno` char(4) NOT NULL,
`cname` varchar(30) NOT NULL,
`credit` smallint(6) DEFAULT NULL,
`ptime` char(5) DEFAULT NULL,
`teacher` char(10) DEFAULT NULL,
PRIMARY KEY (`cno`)
);
CREATE TABLE `sc` (
`sno` char(4) NOT NULL,
`cno` char(4) NOT NULL,
`grade` decimal(6,1) DEFAULT NULL,
PRIMARY KEY (`sno`,`cno`),
CONSTRAINT `fk_sc_cno` FOREIGN KEY (`cno`) REFERENCES `cou` (`CNO`),
CONSTRAINT `fk_sc_sno` FOREIGN KEY (`sno`) REFERENCES `stu` (`sno`)
);
SELECT sno, sname
FROM stu
WHERE NOT EXISTS (
SELECT *
FROM sc
WHERE stu.sno = sc.sno AND cno = 'C语言'
)
ORDER BY sno ASC;
阅读全文