Bsit 32 Content

12
INFORMATION TECHNOLOGY PROGRAMMES BSIT 32 RDBMS VII

Transcript of Bsit 32 Content

BSIT 32 RDBMS

VII

KUVEMPU UNIVERSITYINFORMATION TECHNOLOGY PROGRAMMESBachelor of Science in Information Technology - B.Sc. (IT) Master of Science in Information Technology - M.Sc. (IT)

BSIT - 31 PDP - II BSIT - 32 RDBMS

B.Sc.(IT) - 3 Semesterrd

Directorate of Distrance Education

Kuvempu University

In collaboration with

Universal Education TrustBangalore

Shankaraghatta, Shimoga District, Karnataka

VI

BSIT 32 RDBMS

Titles in this Volume :

BSIT - 32 RDBMS BSIT - 32 RDBMS

Prepared by UNIVERSAL EDUCATION TRUST (UET) Bangalore First Edition : May 2005 Copyright by UNIVERSAL EDUCATION TRUST, Bangalore All rights reserved No Part of this Book may be reproduced in any form or by any means without the written permission from Universal Education Trust, Bangalore. All Product names and company names mentioned herein are the property of their respective owners.

NOT FOR SALE For personal use of Kuvempu University IT - Programme Students only.Corrections & Suggestions for Improvement of Study material are invited by Universal Education Trust, Bangalore. E-mail : [email protected]

Mayur Print AdsPrinted at : Bangalore - 20 Ph : 94480 - 42724

BSIT 32 RDBMS

VII

RDBMS(B S IT - 32)

: Contributing Author :

Phaneendra H. D.

Assistant Professor Department of CS & E The National Institute of Engineering Mysore.

BSIT 32 RDBMS

V

a

Course Introduction

D

atabase and database systems have become an essential component of everyday life in modern society. This book introduces the fundamental concepts necessary for designing, implementing and using database systems. Our presentation stresses the fundamentals of relational model, languages, and facilities provided by the database management systems. This course requires the basic knowledge of database management systems. We also assume that the readers of this book are familiar with elementary programming and data- structuring concepts, and exposure to computer organization. This book has been organized into eight chapters Chapter 1 provides the background material to the subject RDBMS. This chapter covers the basics of relational model. This model has been implemented in a large number of commercial systems over the last twenty-five years. The model uses the concept of a mathematical relation, which looks somewhat like a table of values as its basic building block. We discuss the basic characteristics of the model, its properties, and relational algebra, which is a set of operations for the relational model. Chapter 2 introduces the concept of SQL, the language that we use to extract data from a relational database. SQL is extremely powerful. SQL has become the standard language for most of the commercial database systems products, which uses RDBMS. SQL is concerned with three most common tasks needed by any user of a database management system, namely, data definition, data manipulation, and data control. We discuss here the commands available to carry out these tasks.

Chapter 3 explains the concept behind normalization. Normalization is a successive reduction of a given set of relations to a better form. A normal form specifies the actions needed to remove the drawbacks in the design of the database, leading to creation of a very good database. Here we discuss various normal forms with the help of examples.

VI

BSIT 32 RDBMS

Chapter 4 deals with Oracle architecture. Oracle, currently one of the more widely used RDBMSs for all most all commercial applications. Here we describe the organization of the Oracle system. Oracle stores data in the form of tables. The structure of an Oracle database consists of the definition of the database in terms of schema objects and one or more tablespaces. Chapter 5 covers procedural language called PL/SQL. PL/SQL is Oracles procedural language extension to SQL. We discuss syntax of PL/SQL, its datatypes and declarations, operators, iterative and conditional control, functions and procedures, triggers and cursors. Chapter 6 introduces the concept of remote database system. We introduce, remote procedure call, the technique used to access the remote database. We briefly narrate ODBC, standards developed for interfacing clients and servers, and JDBC, and JDBC API, which connects JAVA applications to database system. Chapter 7 deals with the Internet databases. The World Wide Web (WWW, or Web) is a distributed information system based on hypertext. The Web makes it possible to access a file anywhere on the Internet. We discuss the concept of URL, HTML, XML and search engines. Chapter 8 provides emerging database technologies. Here we discuss the emerging database technologies, which have become increasingly important in the recent years. SQL3 data model, mobile databases, multimedia databases, main memory databases, geographic information systems, temporal and sequence databases, information visualization, genome data management and digital libraries are among the new technology trends.

BSIT 32 RDBMS

VII

Contents

Chapter 1 RELATIONAL MODEL AND RELATIONAL ALGEBRA 1.0 1.1 1.2 Objectives Introduction ............................................................................ Structure of Relational Databases............................................... 1.2.1 Basic Structure of relational data model ........................ 1.2.2 Properties of a relation ................................................ 1.2.3 Keys of a relation ....................................................... 1.2.4 Relational Schema ....................................................... Relational database as an example ............................................. Relational algebra .................................................................... Fundamental operations ............................................................ 1.5.1 The select operation .................................................... 1.5.2 The project operation .................................................. 1.5.3 Composition of relational operators ............................... 1.5.4 The union operation ..................................................... 1.5.5 The set difference operation ........................................ 1.5.6 The Cartesian product operation ................................... 1.5.7 The rename operation .................................................. Additional operations................................................................ 1.6.1 The set intersection operation ....................................... 1.6.2 The natural join............................................................ 1.6.3 The division operation .................................................. 1 1 2 2 3 4 5 68

1.3 1.4 1.5

8 910

1.6

10 11 12 13 16 17 17 17 18

VIII1.7

BSIT 32 RDBMS 1.6.4 The assignment operation ............................................ Summary ................................................................................ Check your progress ............................................................... 19 19 20

Chapter 2 STRUCTURED QUERY LANGUAGE 2.0 2.1 2.2 2.3 Objectives .............................................................................. Introduction ............................................................................ SQL structure ......................................................................... Data Definition Language ......................................................... 2.3.1 The domain of SQL .................................................... 2.3.2 Create command ........................................................ 2.3.3 The drop command ..................................................... 2.3.4 The alter command ..................................................... Data manipulation language ...................................................... 2.4.1 Simple select statement................................................ 2.4.2 The where clause ........................................................ 2.4.3 The from clause .......................................................... 2.4.4 The rename operation with select statement .................. 2.4.4.1 Tuple variables ............................................................ 2.4.5 String operations ......................................................... 2.4.6 Sorting of tuples for display ......................................... 2.4.7 The set operations ...................................................... 2.4.7.1 The union operation ..................................................... 2.4.7.2 The intersect operation ................................................ 2.4.7.3 The except operation ................................................... 2.4.8 Aggregate functions in SQL ......................................... 2.4.9 Group by operations in SQL ......................................... 2.4.10 Null values ................................................................. Nested subqueries ................................................................... 2.5.1 Set membership .......................................................... 2.5.2 Set comparison ........................................................... Modifications to the database .................................................... 2.6.1 Deletion ..................................................................... 2.6.2 Insertion .................................................................... 2.6.3 Updates ..................................................................... 22 22 23 24 24 25 26 27 27 27 29 29 30 30 31 32 32 33 34 34 34 35 36 37 37 38 39 39 39 40

2.4

2.5

2.6

BSIT 32 RDBMS 2.7 Joined relations ........................................................................ 2.7.1 Inner join ................................................................... 2.7.2 Natural join ................................................................ 2.7.3 Left outer join ............................................................. 2.7.4 Join types and conditions .............................................. 2.7.5 Full outer join .............................................................. Embedded SQL ........................................................................ Summary ................................................................................. Check your progress .................................................................

IX41 41 42 43 43 45 45 46 47

2.8 2.9

Chapter 3 NORMALIZATION 3.0 3.1 3.2 3.3 3.4 3.5 Objectives .............................................................................. Introduction ............................................................................ Database design process .......................................................... Normalization .......................................................................... Description of normalization ...................................................... Role of keys ............................................................................ 3.5.1 The role of keys in maintaining relationship .................... 3.5.2 The important keys are ................................................ Unnormalized relations ............................................................. Normal forms .......................................................................... 3.7.1 First normal form ........................................................ 3.7.2 Second normal form .................................................... 3.7.3 Third normal form ....................................................... 3.7.4 Other Normalization forms ........................................... Summary ................................................................................ Check your progress ................................................................ 50 50 52 52 52 53 53 53 54 55 55 56 58 59 63 64

3.6 3.7

3.8

Chapter 4 ORACLE ARCHITECTURE 4.0 4.1 4.2 4.3 Objectives ............................................................................... Introduction ............................................................................ 4.1.1 An Overview of Databases and Instances...................... Internal database structures ...................................................... Internal memory structures ....................................................... 66 66 67 68 71

X

BSIT 32 RDBMS 4.3.1 Global areas ............................................................... 4.3.2 Background process .................................................... External structures .................................................................. Architecture overview .............................................................. Summary ................................................................................ Check your progress ................................................................ 71 72 75 77 78 78

4.4 4.5 4.6

Chapter 5 PL/SQL 5.0 5.1 Objectives .............................................................................. Introduction ............................................................................ 5.1.1 Performance .............................................................. 5.1.2 Portability .................................................................. 5.1.3 What PL/SQL can do for programmers? ....................... The PL/SQL syntax ................................................................. 5.2.1 The block PL/SQL structure ........................................ 5.2.2 The character set ....................................................... 5.2.3 Variables ................................................................... 5.2.4 Literals ...................................................................... 5.2.5 Comments ................................................................. . PL/SQL data types and declarations .......................................... 5.3.1 Declaring variables ..................................................... 5.3.2 Assigning a value to a variable ..................................... 5.3.3 Declaring a constant .................................................... 5.3.4 Picking up a variables parameters from a table cell ....... 5.3.5 An identifier in PL/SQL block....................................... PL/SQL operators ................................................................... 5.4.1 Arithmetic operators .................................................... 5.4.2 Comparison operators .................................................. 5.4.3 Logical operators ........................................................ 5.4.4 String operators .......................................................... Conditional control in PL/SQL ................................................... Iterative control in PL/SQL ....................................................... 5.6.1 Loop statement ........................................................... 5.6.2 While loop .................................................................. 5.6.3 The GOTO statement .................................................. 5.6.4 For Loop .................................................................... 81 81 82 82 82 83 83 84 84 85 85 86 87 87 88 88 89 89 89 90 91 92 92 93 93 94 95 95

5.2

5.3

5.4

5.5 5.6

BSIT 32 RDBMS Error handling in PL/SQL ......................................................... 5.7.1 User defined exceptions ............................................... 5.7.2 Predetermined internal PL/SQL exceptions .................... 5.8 PL/SQL functions and procedures ............................................. 5.8.1 Functions ................................................................... 5.8.2 Procedures ................................................................. 5.9 Database triggers ..................................................................... 5.10 Cursors ................................................................................... 5.10.1 Explicit cursor management .......................................... 5.10.2 Explicit cursor attributes .............................................. 5.11 Summary ................................................................................ Check your progress ................................................................ Chapter 6 REMOTE DATABASE SYSTEM 6.0 6.1 6.2 6.3 6.4 6.5 Objectives ............................................................................... Introduction ............................................................................. Remote procedure calls ............................................................. Transparency issues ................................................................. Introduction to ODBC .............................................................. 6.4.1 ODBC architecture ..................................................... JAVA database introduction ...................................................... 6.5.1 Database design for client/server systems ...................... 6.5.2 Two tier database design .............................................. 6.5.3 Three tier database design ............................................ 6.5.4 JDBC API ................................................................. 6.5.5 How JDBC works ....................................................... 6.5.6 JDBC API components ............................................... 6.5.7 JDBC drivers .............................................................. Summary ................................................................................ Check your progress ................................................................. 5.7

XI99 100 101 104 104 105 106 107 108 111 112 112

6.6

115 115 116 118 120 121 123 123 124 125 126 126 127 128 129 130

XIIChapter 7 INTERNET DATABASES 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9

BSIT 32 RDBMS

Objectives ............................................................................... Introduction ............................................................................. The World Wide Web................................................................. Introduction to HTML................................................................ Databases and the World Wide Web............................................ Architecture............................................................................. Application Servers and Server-side Java.................................... Beyond HTML is it XML ? ........................................................ XML-QL: Querying XML data ................................................... Search engines ......................................................................... 7.9.1 Search tools and Methods ............................................. 7.10 Summary ................................................................................. Check your progress .................................................................

131 131 132 133 135 135 136 139 140 140 141 145 145

Chapter 8 EMERGING DATABASE TECHNOLOGIES 8.0 8.1 8.2 8.3 Objectives ............................................................................... Introduction.............................................................................. SQL3 Object Model .................................................................. Mobile databases ..................................................................... 8.3.1 Mobile Computing Architecture ..................................... 8.3.2 Types of data used in Mobile Computing Applications ...... 8.4 Main memory databases ............................................................ 8.5 Multimedia Databases ............................................................... 8.5.1 Multimedia database applications .................................. 8.6 Geographic Information systems ................................................ 8.7 Temporal and sequence databases .............................................. 8.8 Information Visualization ........................................................... 8.9 Genome data management ......................................................... 8.9.1 Biological sciences and Genetics ................................... 8.9.2 The Genome Database ................................................ 8.10 Digital Libraries ........................................................................ 8.11 Summary ................................................................................. Check your progress ................................................................ 148 148 150 151 152 152 153 154 155 156 157 157 158 158 159 159 160 160