数据库原理吉林大学随笔第11课时

  1. 补充定义外键
    ALTER TABLE<表名> ADD FOREIGN KEY <>
  2. 撤销外键的定义
    7.定义和撤销别名 create synonym 撤销:drop synonym

3.3.4 索引的建立和撤销

3.4.1 基本SQL查询语言


查询2个表中的内容时的两种写法及优劣分析:
有表:student,sc
第一种写法是: select student.sno,sname from student,sc where student.sno=sc.sno and cno='cs-221'
第二种写法是:select sno,sname from student where sno in (select sno from sc where cno='cs-221')(in 是谓词)
第一种写法是两个表做笛卡尔积,因此,数据量大的话会创建一个很大的表,效率是很慢的,第二种写法,是用嵌套查询,有结构化程序设计的特点,清晰,效率高。
第三种写法: select sno,sname from student where EXISTS (select *from sc where sc.sno=student.sno and cno='cs-221' )(exists 是存在量词)
那么问题来了第二种和第三种孰优孰劣呢?
分析发现他们的实质都的对两个表进行的笛卡尔积的操作,那么到底应该用那个表就要根据具体业务的数据量来确定了。

猜你喜欢

转载自www.cnblogs.com/lanhai2020/p/12963078.html