如果在“学生-课程”数据库中,希望当删除Student表中的元组时,级联删除SC表中相应的元组,则在定义SC表时,应有语句____________________。
A: FOREIGN KEY (Sno) ON DELETE CASCADE Student(Sno)
B: FOREIGN KEY (Sno) ON DELETE NO ACTION Student(Sno)
C: FOREIGN KEY (Sno) REFERENCES Student(Sno) ON DELETE NO ACTION
D: FOREIGN KEY (Sno) REFERENCES Student(Sno) ON DELETE CASCADE
A: FOREIGN KEY (Sno) ON DELETE CASCADE Student(Sno)
B: FOREIGN KEY (Sno) ON DELETE NO ACTION Student(Sno)
C: FOREIGN KEY (Sno) REFERENCES Student(Sno) ON DELETE NO ACTION
D: FOREIGN KEY (Sno) REFERENCES Student(Sno) ON DELETE CASCADE
举一反三
- 在“学生-课程”数据库中,若定义SC(Sno, Cno, Grade)时,有子句FOREIGN KEY(Sno) REFERENCES Student(Sno) ON DELETE NO ACTION,且SC表中有学号为201215128的学生选课记录,则执行下列SQL语句后的结果为_________。[img=627x211]1803be1186f523e.png[/img] A: 数据库没有变化 B: 学号为201215128的学生记录被删除掉了 C: 学号为201215128的学生记录和他所有的选课记录都被删除掉了 D: 学号为201215128的学生记录被删除掉了,他所有的选课记录上的学号值变为“NO ACTION”
- 在学生选课数据库中,查询选修了课程的学生的学号、姓名,SQL语句可为( ) A: SELECT DISTINCT Sno, Sname FROM Student, SC WHERE Student.Sno = SC.Sno; B: SELECT Sno, Sname FROM Student, SC WHERE Student.Sno = SC.Sno; C: SELECT DISTINCT Sno, DISTINCT Sname FROM Student WHERE Student.Sno IN (SELECT Sno FROM SC); D: SELECT Sno, Sname FROM Student WHERE Student.Sno IN (SELECT DISTINCT Sno FROM SC);
- 创建学生表:CREATE TABLE Student([br][/br]Sno char(6),[br][/br]Sname varchar(8),[br][/br]Ssex char(2),[br][/br]Sbirth DATE,[br][/br]Sdept varchar(30)[br][/br]);[br][/br]现在要添加主键的代码正确的是( )。 A: ALTER TABLE student ADD PRIMARY KEY(Sno); B: ALTER TABLE student ADD PRIMARY KEY Sno ; C: ALTER TABLE student ADD unique (Sno); D: ALTER TABLE student PRIMARY KEY(Sno);
- 下述 SQL 命令的短语中,定义属性上约束条件的是( [br][/br] ) 创建系部表 CREATE TABLE Department( Sdept varchar(20) PRIMARY KEY, PIC varchar(8), Adress varchar(20) ); 创建学生表 CREATE TABLE Student( Sno char(6) PRIMARY key, Sname varchar(8), Ssex char(2), Sbirth DATE, Sdept varchar(20), FOREIGN key(Sdept)REFERENCES department(Sdept) ON DELETE SET NULL ON UPDATE CASCADE [br][/br] ); 下列描述不正确的是( ) A: 删除Department表中的元组时,Student相应的元组对应值置空 B: Department表中插入元组时,Student也自动插入新的元组 C: Department表中元组更新时,Student相应的元组对应值也更新 D: 设置了student表中的sdept为外码
- 下列 SQL 语句select * from student where sno = '05880101'union select * from student where sno = '05880102'与此查询语句等价的选项是( )。 A: select * from student where sno= '05880101' and sno= '05880102' B: select * from student where sno= '05880101' or sno= '05880102' C: select * from student where sno= '05880101' D: select * from student where sno= '05880102'