Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Database System An Introduction to Database System

Similar presentations


Presentation on theme: "An Introduction to Database System An Introduction to Database System"— Presentation transcript:

1 An Introduction to Database System An Introduction to Database System
数据库系统概论 An Introduction to Database System 第十五章 对象关系数据库系统 中国人民大学信息学院 An Introduction to Database System

2 An Introduction to Database System
对象关系数据库系统 对象关系数据库系统(Object Relational Database System,ORDBS)是面向对象数据模型(Object Oriented Data Model,简称OO模型)和关系数据模型相结合的产物 三条研究路线 以面向对象的程序设计语言为基础,研究持久的程序设计语言,支持OO模型; 建立新的面向对象数据库系统OODBS,支持OO数据模型; 以关系数据库和SQL为基础,把面向对象技术融入数据库系统的ORDBS An Introduction to Database System

3 An Introduction to Database System
第十五章 对象关系数据库系统 15.1 面向对象数据模型 15.2 对象-关系数据库 15.3 小结 An Introduction to Database System

4 An Introduction to Database System
15.1 面向对象数据模型 面向对象数据库系统支持OO模型 面向对象数据库系统:一个持久的、可共享的对象库的存储和管理者 对象库:由一个OO模型所定义的对象的集合体 An Introduction to Database System

5 An Introduction to Database System
15.1 面向对象数据模型 OO模型的核心概念 类层次(结构) 继承 对象的嵌套 An Introduction to Database System

6 An Introduction to Database System
OO模型的核心概念 1.对象 定义:对象是由一组数据结构和在这组数据结构上的操作的程序代码封装起来的基本单位。 组成部分 属性(Attribute)集合 属性描述对象的状态、组成和特性 方法(Method)集合 描述了对象的行为特性 An Introduction to Database System

7 An Introduction to Database System
OO模型的核心概念(续) 2. 对象标识OID(Object IDentifier) 概念:面向对象数据库中的每个对象都有一个唯一的不变的标识称为对象标识(OID) 特点: 永久持久性 独立于值的、系统全局唯一的 An Introduction to Database System

8 An Introduction to Database System
OO模型的核心概念(续) 3. 封装(Encapsulation) 每一个对象是其状态与行为的封装 封装是对象的外部界面与内部实现之间实行清晰隔离的一种抽象,外部与对象的通信只能通过消息 对象封装之后查询属性值必须通过调用方法 An Introduction to Database System

9 An Introduction to Database System
OO模型的核心概念(续) 4. 类(Class) 对象类(简称类):共享同样属性和方法集的所有对象构成了一个对象类 实例:一个对象是某一类的一个实例(instance) 在OODB中,类是“型”,对象是某一类的一个“值” An Introduction to Database System

10 An Introduction to Database System
15.1 面向对象数据模型 OO模型的核心概念 类层次(结构) 继承 对象的嵌套 An Introduction to Database System

11 An Introduction to Database System
类层次(结构)(续) 图15.1 学校数据库的类层次结构图 教员、行政人员、工人中只有本身的特殊属性和方法 同时它们又继承教职员工类和人的所有属性和方法 逻辑上它们具有人、教职员工和本身的所有属性和方法 An Introduction to Database System

12 An Introduction to Database System
类层次(结构)(续) 超类/子类之间的关系体现了“IS A”的语义 超类是子类的抽象(Generalization)或概括 子类是超类的特殊化(Specialization)或具体化 类层次可以动态扩展,一个新的子类能从一个或多个已有类导出 An Introduction to Database System

13 An Introduction to Database System
15.1 面向对象数据模型 OO模型的核心概念 类层次(结构) 继承 对象的嵌套 An Introduction to Database System

14 An Introduction to Database System
继承 单继承:一个子类只能继承一个超类的特性(包括属性和方法) 层次结构图是一棵树 多重继承:一个子类能继承多个超类的特性 层次结构图是一个带根的有向无回路图 An Introduction to Database System

15 An Introduction to Database System
继承(续) 多重继承 具有多继承的类层次结构图 An Introduction to Database System

16 An Introduction to Database System
继承(续) 继承性的优点 第一,建模的有力工具,提供了对现实世界简明而精确的描述 第二,提供了信息重用机制 子类与超类的冲突 子类在定义自己特殊属性和方法时可能与继承下来的超类的属性和方法发生冲突 由系统解决 An Introduction to Database System

17 An Introduction to Database System
15.1 面向对象数据模型 OO模型的核心概念 类层次(结构) 继承 对象的嵌套 An Introduction to Database System

18 An Introduction to Database System
对象的嵌套 对象嵌套: 一个对象的属性可以是一个对象,这样对象之间产生一个嵌套层次结构 设Obj1和Obj2是两个对象。如果Obj2是Obj1的某个属性的值,称Obj2属于Obj1,或Obj1包含Obj2。 复杂对象 子对象 嵌套层次结构 An Introduction to Database System

19 An Introduction to Database System
对象的嵌套(续) 汽车的嵌套层次图 An Introduction to Database System

20 An Introduction to Database System
对象的嵌套(续) 对象嵌套层次结构和类层次结构形成了对象横向和纵向的复杂结构 各种类之间具有层次结构 某一个类内部也具有嵌套层次结构 An Introduction to Database System

21 An Introduction to Database System
关系模型与OO模型的比较 表15.1 关系数据模型与OO模型的比较 内容 关系数据模型 面向对象数据模型 基本数据结构 二维表 数据标识符 OID 静态性质 属性 动态行为 关系操作 方法 抽象数据类型 封装性 数据间关系 主外码联系,数据依赖 继承、组合 模式演化能力 An Introduction to Database System

22 An Introduction to Database System
第十五章 对象关系数据库系统 15.1 面向对象数据模型 15.2 对象-关系数据库 15.3 小结 An Introduction to Database System

23 An Introduction to Database System
15.2 对象-关系数据库 对象关系数据库系统中扩展的关系数据类型 对象关系数据库系统中扩展的对象类型及其定义 参照类型(Reference Type) 继承性 子表和超表 An Introduction to Database System

24 An Introduction to Database System
对象关系数据库系统中扩展的关系数据类型 扩展的类型: LOB BOOLEAN 集合类型ARRAY 用户定义的DISTINCT类型等 面向对象的数据类型 行类型ROW TYPE 抽象数据类型(Abstract Data Type) An Introduction to Database System

25 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 大对象LOB(Large OBject )类型 LOB可存储多达十亿字节的串。 LOB分类 二进制大对象BLOB(Binary Large OBject) BLOB用于存储音频、图像数据 字符串大对象CLOB(Character Large OBject)。 CLOB用于存储长字符串数据 An Introduction to Database System

26 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 2. BOOLEAN类型 布尔类型,支持3个真值:true、false和unknown 操作符:NOT、AND、OR、EVERY、ANY 例如 WHERE EVERY(QTY>200) 或WHERE ANY(QTY>200) QTY列为空值:返回unknown; QTY列为非空: 当该列的每一个值都使(QTY>200)为true时,EVERY返回true,否则为false; 当该列的每一个值都使(QTY>200)为false时,ANY返回false,否则为true。 An Introduction to Database System

27 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 3.集合类型(Collection Type)ARRAY 相同类型元素的有序集合称为数组ARRAY SQL3新增的集合类型 允许在数据库的一列中存储数组 SQL3的数组只能是一维的 数组中的元素不能再是数组 An Introduction to Database System

28 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) [例2] CREATE TABLE SALES ( ITEM_NO CHAR(20), /*商品号*/ QTY INTEGER ARRAY[12], /*整数数组,存放销售额*/ PRIMARY KEY(ITEM_NO) ); An Introduction to Database System

29 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 向SALES表插入一个元组: INSERT INTO SALES(ITEM_NO,QTY)VALUES (‘T-shirt2000’,ARRAY[200,150,200,100,50,70, ,200,10,20,100,200]); 查找三月份销售额大于100的商品号: SELECT ITEM_NO FROM SALES WHERE QTY[3]>100; An Introduction to Database System

30 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 4. DISTINCT类型 SQL3新加了一种DISTINCT类型 定义DISTINCT数据类型语法 CREAT TYPE <type name> AS <built in scalar type name> FINAL [ <cast option>] [ <method specification commalist>]; An Introduction to Database System

31 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 没有使用DISTINCT类型 例如,职工的智商字段(IQ)和鞋号字段(SHOE_SIZE)定义成INTEGER类型 WHERE SHOE_SIZE > IQ An Introduction to Database System

32 An Introduction to Database System
ORDBS中扩展的关系数据类型(续) 使用DISTINCT类型 重新定义这两字段类型 CREAT TYPE SHOE_SIZE_TYPE AS INTEGER FINAL; CREAT TYPE IQ_TYPE AS INTEGER FINAL; SHOE_SIZE_TYPE和IQ _TYPE成为两种不同的数据类型 表达式:WHERE SHOE_SIZE > IQ 是非法的 如果在定义类型时设置了选项<cast option>,下面用法也是合法的:WHERE MY_SHOE_SIZE > CAST (MY_IQ AS SHOE_SIZE) An Introduction to Database System

33 An Introduction to Database System
15.2 对象-关系数据库 对象关系数据库系统中扩展的关系数据类型 对象关系数据库系统中扩展的对象类型及其定义 参照类型(Reference Type) 继承性 子表和超表 An Introduction to Database System

34 An Introduction to Database System
ORDBS中扩展的对象类型及其定义 在ORDBMS中,类型(TYPE)具有类(CLASS)的特征,可以看成类 1.行对象与行类型 定义行类型(ROW TYPE) : CREATE ROW TYPE <row_type_name> (<component declarations>); An Introduction to Database System

35 ORDBS中扩展的对象类型及其定义(续)
创建行类型 [例3] CREATE ROW TYPE Person_type (pno NUMBER, name VARCHAR2(100), address VARCHAR2(100) ); An Introduction to Database System

36 ORDBS中扩展的对象类型及其定义(续)
创建基于行类型的表 CREATE TABLE <table_name> OF <row_type_name>; [例4] CREATE TABLE person_extent OF Person_type (pno PRIMARY KEY ); An Introduction to Database System

37 ORDBS中扩展的对象类型及其定义(续)
2.列对象与对象类型 可以创建一个对象类型,表的属性可以是该对象类型。 创建列对象语句如下: CREATE TYPE <type_name> AS OBJECT (<component declarations>); An Introduction to Database System

38 ORDBS中扩展的对象类型及其定义(续)
[例5] CREATE TYPE address_objtyp AS OBJECT (street VARCHAR2(50), city VARCHAR2(50) ); CREATE TYPE name_objtyp AS OBJECT (first_name VARCHAR2(30), last_name VARCHAR2(30) ) ; An Introduction to Database System

39 ORDBS中扩展的对象类型及其定义(续)
创建表,定义其中的属性是对象类型 [例6] CREATE TABLE people_reltab ( Id NUMBER(10), name_obj name_objtyp, address_obj address_objtyp); An Introduction to Database System

40 ORDBS中扩展的对象类型及其定义(续)
3. 抽象数据类型(Abastract Data Type,ADT) 概念:SQL3允许用户创建指定的带有自身行为说明和内部结构的用户定义类型称为抽象数据类型 定义ADT的一般形式为   CREATE TYPE <type_name> (   所有属性名及其类型说明,   [定义该类型的等于=和小于<函数,]   定义该类型其他函数(方法)); An Introduction to Database System

41 An Introduction to Database System
ADT的特点 (1) ADT的属性定义和行类型的属性定义类同。 (2) 在创建ADT的语句中,通过用户定义的函数比较对象的值。 (3) ADT的行为通过方法(methods)、函数(functions)实现。 (4) SQL3要求抽象数据类型是封装的,而行类型则不要求封装。 (5) ADT有3个通用的系统内置函数 (6) ADT可以参与类型继承 An Introduction to Database System

42 An Introduction to Database System
15.2 对象-关系数据库 对象关系数据库系统中扩展的关系数据类型 对象关系数据库系统中扩展的对象类型及其定义 参照类型(Reference Type) 继承性 子表和超表 An Introduction to Database System

43 An Introduction to Database System
参照类型(Reference Type) REF类型(参照类型、引用类型) 引入的原因: 类型之间可能具有相互参照的联系 形式   REF <类型名> 特点: REF类型总是和某个特定的类型相联系。 它的值是OID An Introduction to Database System

44 An Introduction to Database System
参照类型(续) 创建两个表:Employee和Company,两表之间存在相互参照关系,即某个职工在某个公司工作 (1)创建行类型 [例7] CREATE ROW TYPE employee_type( name VARCHAR(35), age INTEGER ); CREATE ROW TYPE Comp_ type( compname VARCHAR(20), location VARCHAR(20) ); An Introduction to Database System

45 An Introduction to Database System
参照类型(续) (2)创建基于行类型的表: CREATE TABLE Employee OF employee_type; CREATE TABLE Company OF Comp_ type (3)描述参照关系 CREATE ROW TYPE Employment _type ( employee REF (employee_type), company REF (Comp_ type) ); CREATE TABLE Employment OF Employment _type 表Employment中某一个元组的employee属性值是某个职工的OID company属性值是该职工所在公司的OID An Introduction to Database System

46 An Introduction to Database System
参照类型(续) [例8] CREATE ROW TYPE employee_type( name VARCHAR(35), age INTEGER, emp_id REF(employee_type) ); [例9] CREATE TABLE Employee OF employee_type VALUES FOR emp_id ARE SYSTEM GENERATED; An Introduction to Database System

47 An Introduction to Database System
参照类型(续) 建立参照属性: <参照属性名>[REF(<类型名>)]SCOPE IS <关系名> [例10] CREATE TABLE address_objtab OF address_objtyp ; [例11] CREATE TABLE people_reltab2 ( id NUMBER(4) PRIMARY KEY, name_obj name_objtyp, addresss_ref REF(address_objtyp) SCOPE IS address_objtab ) An Introduction to Database System

48 An Introduction to Database System
参照类型(续) [例12] CREATE INDEX address_ref_idx ON people_reltab2(address_ref) ; [例13] SELECT id FROM people_reltab2 p WHERE p.address_ref.city='北京' and p.address_ref.street='牛街'; An Introduction to Database System

49 An Introduction to Database System
15.2 对象-关系数据库 对象关系数据库系统中扩展的关系数据类型 对象关系数据库系统中扩展的对象类型及其定义 参照类型(Reference Type) 继承性 子表和超表 An Introduction to Database System

50 An Introduction to Database System
继承性 ORDBMS应该支持继承性 一般是单继承性 [例14] CREATE TYPE emp_type UNDER person_type AS( emp_id INTEGER, salary REAL ) NOT FINAL; NOT FINAL:表示不是类层次结构中最后的“叶结点” FINAL:该类型是类层次结构的叶结点 An Introduction to Database System

51 An Introduction to Database System
15.2 对象-关系数据库 对象关系数据库系统中扩展的关系数据类型 对象关系数据库系统中扩展的对象类型及其定义 参照类型(Reference Type) 继承性 子表和超表 An Introduction to Database System

52 An Introduction to Database System
子表和超表 超表、子表、子表的子表构成一个表层次结构 表层次和类型层次的概念十分相似 An Introduction to Database System

53 An Introduction to Database System
子表和超表(续) [例15] 对于下面的类型层次,先定义这些类型TYPE,然后创建基于这些类型的表 类型层次示例 An Introduction to Database System

54 An Introduction to Database System
子表和超表(续) CREATE TYPE person /*创建person 类型,根类型*/ (id INTEGER, name VARCHAR(20), birthyear INTEGER, address VARCHAR(40)) NOT FINAL; /*NOT FINAL表示可以有子类型*/ CREATE TYPE employee /*创建person的子类型employee*/ UNDER person /*类型employee继承person的属性*/ (salary INTEGER) /* employee定义自己的属性*/ NOT FINAL; An Introduction to Database System

55 An Introduction to Database System
子表和超表(续) CREATE TYPE executive /*创建employee的子类型executive*/ UNDER employee (bonus INTEGER) FINAL; CREATE TYPE student /*创建person的子类型student */ UNDER person (major VARCHAR(10),wage DECIMAL) FINAL An Introduction to Database System

56 An Introduction to Database System
子表和超表(续) [例16]Department类型和employee具有相互参照的联系,使用REF来表示这种联系 CREATE TYPE department (ID INTEGER, manager REF(employee), Budget INTEGER); ALTER TYPE employee ADD ATTRIBUTE dept REF(department); An Introduction to Database System

57 An Introduction to Database System
子表和超表(续) 定义基于这些类型的基本表和表层次: CREATE TABLE person_table OF person (name WITH OPTIONS NOT NULL); employee_table是 person_table的子表 CREATE TABLE employee_table OF employee UNDER person_table; CREATE TABLE exec_table of executive UNDER employee_table An Introduction to Database System

58 An Introduction to Database System
子表和超表(续) CREATE TABLE student_table OF student UNDER person_table; CREATE TABLE dept_table OF department (manager SCOPE IS employee_table); ALTER TABLE employee_table ALTER COLUMN dept ADD SCOPE IS dept_table; An Introduction to Database System

59 An Introduction to Database System
子表和超表(续) 查询[例16]所创建的表 [例17] SELECT name,address FROM person_table WHERE birthyear <=1970; An Introduction to Database System

60 An Introduction to Database System
子表和超表(续) 关闭子表的检索 [例18] SELECT name,address FROM ONLY person_table WHERE birthyear <=1970; An Introduction to Database System

61 An Introduction to Database System
子表和超表(续) INSERT、DELETE、UPDATE对子表和超表的操作规则 INSERT:向子表插入一行时一般会在该子表的超表上也插入一行。 DELETE:从表删除一行时一般会在该表的超表和子表上也删除相应的一行 An Introduction to Database System

62 An Introduction to Database System
第十五章 对象关系数据库系统 15.1 面向对象数据模型 15.2 对象-关系数据库 15.3 小结 An Introduction to Database System

63 An Introduction to Database System
15.3 小结 OO模型的基本概念 对象 对象标识OID 封装 对象关系数据库系统中扩展的关系数据类型 大对象LOB BOOLEAN类型 集合类型ARRAY DISTINCT类型 An Introduction to Database System

64 An Introduction to Database System
小结(续) 对象关系数据库系统中扩展的对象类型 行对象与行类型 列对象与对象类型 抽象数据类型 关系对象数据库系统支持 继承 子表和超表 An Introduction to Database System


Download ppt "An Introduction to Database System An Introduction to Database System"

Similar presentations


Ads by Google

玻璃钢生产厂家商场动漫美陈青花瓷玻璃钢花盆价格表四川节庆商场美陈制作淅川玻璃钢雕塑定制赣州玻璃钢雕塑厂乡宁玻璃钢花盆花器玻璃钢景观雕塑免费咨询郑州铜玻璃钢彩绘雕塑定做价格河北保定玻璃钢雕塑工艺差吗扬州玻璃钢雕塑景观设计鼎湖玻璃钢造型雕塑公司小品玻璃钢卡通雕塑规格玻璃钢雕塑墙面安装高邮玻璃钢浮雕人物山水雕塑长春玻璃钢雕塑定制公司金山区拉丝玻璃钢雕塑推荐浙江玻璃钢仿真水果雕塑价格玻璃钢花盆栽装饰玻璃钢着色雕塑修复淮安玻璃钢花盆花器晋城铜玻璃钢人物雕塑公司温州玻璃钢花盆定制保山玻璃钢雕塑批发商宿州玻璃钢雕塑生产厂家驻马店玻璃钢卡通雕塑茂名玻璃钢雕塑沙发福建季节性商场美陈厂家直销云南玻璃钢雕塑加工怀化公园玻璃钢雕塑订制驻马店佛像玻璃钢彩绘雕塑香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化