版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Chapter 9: Object-Based Databases,Complex Data Types and Object Orientation Structured Data Types and Inheritance in SQL Table Inheritance Array and Multiset Types in SQL Object Identity and Reference Types in SQL Implementing O-R Features Persistent Programming Languages Comparison of Object-Orient
2、ed and Object-Relational Databases,Overview,Traditional database applications: Large amount of relatively simple type of data; Short and simple transaction (task); Some new applications need data management support. With complex data type: computer aided design(CAD) and geographical information syst
3、ems(GIS) Object-Relational Database system; Object-Oriented Database System; With long and complex tasks: very complex data analysis. Data warehouse and Data Mining,Object-Relational Vs Object Oriented,Object-Relational Based on traditional Relational Data model Extend the data model to support comp
4、lex data type, including object orientation and constructs to deal with added data types. Allow attributes of tuples to have complex types, including non-atomic values such as nested relations. Preserve relational foundations, in particular the declarative access to data, while extending modeling po
5、wer. Driven by commercial DBMS vendors. Object-Oriented Based on object-oriented programming languages, such as C+,Java; Extend the data persistency feature to the programming language to support data storage and manipulation.,Complex Types and SQL:1999,Extensions to SQL to support complex types inc
6、lude: Collection and large object types Nested relations are an example of collection types Structured types Nested record structures like composite attributes Inheritance Object orientation Including object identifiers and references Our description is mainly based on the SQL:1999 standard Not full
7、y implemented in any database system currently But some features are present in each of the major commercial database systems Read the manual of your database system to see what it supports,Structured Types and Inheritance in SQL,Structured types can be declared and used in SQL create type Name as (
8、firstname varchar(20), lastname varchar(20) final create type Address as (street varchar(20), city varchar(20), zipcode varchar(20) not final Note: final and not final indicate whether subtypes can be created Structured types can be used to create tables with composite attributes create table custom
9、er ( name Name, address Address, dateOfBirth date) Dot notation used to reference components: name.firstname,Structured Types (cont.),User-defined row types create type CustomerType as ( name Name, address Address, dateOfBirth date) not final Can then create a table whose rows are a user-defined typ
10、e create table customer of CustomerType,Methods,Can add a method declaration with a structured type. method ageOnDate (onDate date) returns interval year Method body is given separately. create instance method ageOnDate (onDate date) returns interval year for CustomerType begin return onDate - self.
11、dateOfBirth; end We can now find the age of each customer: select name.lastname, ageOnDate (current_date) from customer,Inheritance,Suppose that we have the following type definition for people: create type Person (name varchar(20), address varchar(20) Using inheritance to define the student and tea
12、cher types create type Student under Person (degree varchar(20), department varchar(20) create type Teacher under Person (salary integer, department varchar(20) Subtypes can redefine methods by using overriding method in place of method in the method declaration,Multiple Inheritance,SQL:1999 and SQL
13、:2003 do not support multiple inheritance If our type system supports multiple inheritance, we can define a type for teaching assistant as follows: create type Teaching Assistant under Student, Teacher To avoid a conflict between the two occurrences of department we can rename them create type Teach
14、ing Assistant under Student with (department as student_dept ), Teacher with (department as teacher_dept ),Consistency Requirements for Subtables,Consistency requirements on subtables and supertables. Each tuple of the supertable (e.g. people) can correspond to at most one tuple in each of the immed
15、iate subtables (e.g. students and teachers) That is, no overlap among subtables. Additional constraint in SQL:1999: All tuples corresponding to each other (that is, with the same values for inherited attributes) must be derived from one tuple (inserted into one table). That is, each entity must have
16、 a most specific type We cannot have a tuple in people corresponding to a tuple each in students and teachers,Array and Multiset Types in SQL,Example of array and multiset declaration: create type Publisher as (name varchar(20), branch varchar(20) create type Book as (title varchar(20), author-array
17、 varchar(20) array 10, pub-date date, publisher Publisher, keyword-set varchar(20) multiset ) create table books of Book Similar to the nested relation books, but with array of authors instead of set,Creation of Collection Values,Array construction array Silberschatz,Korth,Sudarshan Multisets multis
18、etset computer, database, SQL To create a tuple of the type defined by the books relation: (Compilers, arraySmith,Jones, Publisher (McGraw-Hill,New York), multiset parsing,analysis ) To insert the preceding tuple into the relation books insert into books values (Compilers, arraySmith,Jones, Publishe
19、r (McGraw-Hill,New York), multiset parsing,analysis ),Querying Collection-Valued Attributes,To find all books that have the word “database” as a keyword, select title from books where database in (unnest(keyword-set ) We can access individual elements of an array by using indices E.g.: If we know th
20、at a particular book has three authors, we could write: select author-array1, author-array2, author-array3 from books where title = Database System Concepts To get a relation containing pairs of the form “title, author-name” for each book and each author of the book select B.title, A.author from boo
21、ks as B, unnest (B.author-array) as A (author ) To retain ordering information we add a with ordinality clause select B.title, A.author, A.position from books as B, unnest (B.author-array) with ordinality as A (author, position ),Unnesting,The transformation of a nested relation into a form with few
22、er (or no) relation-valued attributes us called unnesting. E.g. select title, A.author, as pub_name, publisher.branch as pub_branch, K.keyword from books as B, unnest(B.author_array ) as A (author ), unnest (B.keyword_set ) as K (keyword ),Nesting,Nesting is the opposite of unnesting,
23、 creating a collection-valued attribute NOTE: SQL:1999 does not support nesting Nesting can be done in a manner similar to aggregation, but using the function collect() in place of an aggregation operation, to create a multiset To nest the flat-books relation on the attribute keyword: select title,
24、author, Publisher (pub_name, pub_branch ) as publisher, collect (keyword) as keyword_set from flat-books groupby title, author, publisher To nest on both authors and keywords: select title, collect (author ) as author_set, Publisher (pub_name, pub_branch) as publisher, collect (keyword ) as keyword_
25、set from flat-books group by title, publisher,1NF Version of Nested Relation,1NF version of books,flat-books,Nesting (Cont.),Another approach to creating nested relations is to use subqueries in the select clause. select title, array ( select author from authors as A where A.title = B.title order by
26、 A.position) as author_array, Publisher (pub-name, pub-branch) as publisher, multiset (select keyword from keywords as K where K.title = B.title) as keyword_set from books4 as B,Object-Identity and Reference Types,Object oriented language provide the ability to refer to objects. In SQL, we can defin
27、e this reference type using object-identity. E.g. Define a type Department with a field name and a field head which is a reference to the type Person, with table people as scope: create type Department ( name varchar (20), head ref (Person) scope people) We can then create a table departments as fol
28、lows create table departments of Department We can omit the declaration scope people from the type declaration and instead make an addition to the create table statement: create table departments of Department (head with options scope people),Object-Identifier,The type of the object-identifier must
29、be specified as part of the type definition of the referenced table There are several ways of generating object-identifier System generated; User defined. Use primary key as object-identifier,System generated OID,We can define the Object Identifier as: Create table people of Person Ref is person_id
30、system generated To create a tuple with a reference value, we can first create the tuple with a null reference and then set the reference separately: insert into departments values (CS, null) update departments set head = (select p.person_id from people as p where name = John) where name = CS,User G
31、enerated Identifiers,The table definition can specify that the reference is user generated create type Person (name varchar(20) address varchar(20) ref using varchar(20) create table people of Person ref is person_id user generated When creating a tuple, we must provide a unique value for the identi
32、fier: insert into people (person_id, name, address ) values (01284567, John, 23 Coyote Run) We can then use the identifier value when inserting a tuple into departments insert into departments values(CS, 02184567),Using Primary Key as OID,Can use an existing primary key value as the identifier: crea
33、te type Person (name varchar (20) primary key, address varchar(20) ref from (name) create table people of Person ref is person_id derived When inserting a tuple for departments, we can then use insert into departments values(CS,John),Path Expressions,Find the names and addresses of the heads of all
34、departments: select head name, head address from departments An expression such as “headname” is called a path expression Path expressions help avoid explicit joins If department head were not a reference, a join of departments with people would be required to get at the address Makes expressing the
35、 query much easier for the user,Implementing O-R Features,Similar to how E-R features are mapped onto relation schemas Subtable implementation Each table stores primary key and those attributes defined in that table or, Each table stores both locally defined and inherited attributes,Persistent Progr
36、amming Languages,Languages extended with constructs to handle persistent data Programmer can manipulate persistent data directly no need to fetch it into memory and store it back to disk (unlike embedded SQL) Persistent objects: by class - explicit declaration of persistence by creation - special sy
37、ntax to create persistent objects by marking - make objects persistent after creation by reachability - object is persistent if it is declared explicitly to be so or is reachable from a persistent object,Systems,Early to middle1990s, Object Oriented Database system was very hot, many Persistent versions of C+ system were built. However, the market for such d
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/SDJSXH 07-2024塔式起重机自动驾驶系统应用技术规程
- T/JX 001-2024喷水织机行业中水回用水质要求
- T/CCSAS 052-2025三氯氢硅还原法多晶硅生产安全技术规范
- T/CCPA 74-2025公路与市政工程预制混凝土构件智能工厂技术要求
- T/CSMT HJ005-2026产品碳足迹数据质量溯源性要求
- GB/T 48281-2026航空器操纵钢丝绳套管尺寸与载荷
- 2025~2026学年广西壮族自治区玉林市陆川县人教版六年级上册11月期中数学试卷【附答案】
- 甘肃省定西市2027届七上数学期末调研模拟试题含解析
- PHP常用复试面试题及详细答案(真实职场版)
- 等电位联结端子箱安装接线方案
- 阿拉善盟教师招聘真题2025
- 湖南省长沙市2026-2027学年高一上学期期中考试语文自编卷(范围:统编版必修一1-4单元)(原卷版)
- 2026年食品标签标识规范业务考试试卷试题及答案
- GJB 151C-2024 军用设备和分系统 电磁发射和敏感度要求与测量
- ISO9001-2026质量管理体系标准培训
- 2026版公路水运工程试验检测专业技术人员职业资格考试《桥隧工程一本通》
- IPC-JEDEC J-STD-020F-2024 中文版(非气密固态表面贴装器件的潮湿 - 再流焊敏感度分级)
- 2025浙江鹿城农商银行春季招聘笔试历年典型考题及考点剖析附带答案详解
- 2026国家电投集团所属国家核电招聘(41人)笔试历年典型考点题库附带答案详解
- 智慧城市重大危险源在线监控及事故预警平台规划方案
- 2025四川绵阳市绵投置地有限公司人力资源岗等岗位拟录用人选笔试历年参考题库附带答案详解
评论
0/150
提交评论