Introduction to Oracle: SQL and PL/SQL Using Procedure Builder... Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xivProfile Before You Begin This Course Before you begin
Trang 1Introduction to Oracle: SQL and PL/SQL Using Procedure Builder
Trang 2Copyright EĂOracle Corporation, 1992, 1996 All rights reserved.
This documentation contains proprietary information of Oracle Corporation; it is provided under a license agreement containing restrictions on use and discloĆ sure and is also protected by copyright law Reverse engineering of the software
is prohibited If this documentation is delivered to a U.S Government Agency of the Department of Defense, then it is delivered with Restricted Rights and the folĆ lowing legend is applicable:
Restricted Rights Legend Use, duplication or disclosure by the Government is subject to restrictions for commercial computer software and shall be deemed to be Restricted Rights softĆ ware under Federal law, and as set forth in subparagraph (c) (1) (ii) of DFARS 252.227Ć7013, Rights in Technical Data and Computer Software (October 1988) This material or any portion of it may not be copied in any form or by any means without the express prior written permission of the Worldwide Education Services group of Oracle Corporation Any other copying is a violation of copyright law and may result in civil and/or criminal penalties.
If this documentation is delivered to a U.S Government Agency not within the DeĆ partment of Defense, then it is delivered with Restricted Rights," as defined in FAR 52.227Ć14, Rights in DataĆGeneral, including Alternate III (June 1987) The information in this document is subject to change without notice If you find any problems in the documentation, please report them in writing to Worldwide Education Services, Oracle Corporation, 500 Oracle Parkway, Box 659806, RedĆ wood Shores, CA 94065 Oracle Corporation does not warrant that this document
is error free.
SQL*Plus, PL/SQL, Procedure Builder, Developer/2000, Oracle7 Server, Oracle Server, Discoverer/2000, and Designer/2000 are trademarks or registered tradeĆ marks of Oracle Corporation.
All other products or company names are used for identification purposes only, and may be trademarks of their respective owners.
Trang 3Volume 1
Preface xi
Profile xii
Related Publications xviii
Typographic Conventions xix
I Introduction IĆ1 Course Objectives IĆ3 Course Outline IĆ5 The Relational Database Concept IĆ9 System Development Cycle IĆ17 What Is Oracle? IĆ19 The Oracle Product Set IĆ21 SQL, SQL*Plus, and PL/SQL IĆ23 Summit Sporting Goods Demonstration Tables IĆ29 Summary IĆ33
1 Selecting Rows 1Ć1 Objectives 1Ć3 The Basic Query Block 1Ć5 Arithmetic Expressions 1Ć13 Column Aliases 1Ć21 The Concatenation Operator 1Ć23 Literal Character String 1Ć25 Managing Null Values 1Ć27 Preventing the Selection of Duplicate Rows 1Ć31 SQL*Plus Commands 1Ć35 Logging in to SQL*Plus 1Ć37 Displaying Table Structure 1Ć39 SQL*Plus Editing Commands 1Ć41 SQL*Plus File Commands and Online Help 1Ć43
Trang 4Negating Expressions 2Ć17 SQL Operators 2Ć19 Querying Data with Multiple Conditions 2Ć27 Rules of Precedence 2Ć29 Summary 2Ć33 Practice Overview 2Ć35 Practice 2 2Ć37
3 Single Row Functions 3Ć1 Objectives 3Ć3 Overview 3Ć5 Single Row Functions 3Ć7 Character Functions 3Ć9 Number Functions 3Ć17 Oracle Date Format 3Ć23 Using Arithmetic Operators with Dates 3Ć25 Date Functions 3Ć27 Conversion Functions 3Ć33 TO_CHAR Function with Date Formats 3Ć35 TO_CHAR Function with Number Formats 3Ć45 TO_NUMBER and TO_DATE Functions 3Ć49 Nesting Single Row Functions 3Ć51 Nesting Functions 3Ć53 Summary 3Ć55 Practice Overview 3Ć57 Practice 3 3Ć59
4 Displaying Data from Multiple Tables 4Ć1 Objectives 4Ć3 Overview 4Ć5 What Is a Cartesian Product? 4Ć7 Simple Join Query 4Ć9 Using Table Aliases 4Ć17 NonĆEquijoin 4Ć19 Returning Records with No Direct Match 4Ć21 Joining a Table to Itself 4Ć25 Summary 4Ć27 Practice Overview 4Ć29 Practice 4 4Ć31
5 Group Functions 5Ć1 Objectives 5Ć3 Overview 5Ć5 Group Functions 5Ć7
Trang 5The GROUP BY Clause 5Ć13 Illegal Queries Using Group Functions 5Ć19 Groups Within Groups 5Ć23 The HAVING Clause 5Ć25 Summary 5Ć31 Practice Overview 5Ć33 Practice 5 5Ć34
6 Subqueries 6Ć1 Objectives 6Ć3 Overview 6Ć5 Subqueries 6Ć7 How Are Nested Subqueries Processed? 6Ć9 Single Row Subqueries 6Ć11 Errors with Subqueries 6Ć15 Multiple Row Subqueries 6Ć17 HAVING Clause with Nested Subqueries 6Ć19 Summary 6Ć21 Practice Overview 6Ć23 Practice 6 6Ć25Volume 2
7 Specifying Variables at Runtime 7Ć1 Objectives 7Ć3 Overview 7Ć5 Substitution Variables 7Ć7 Single Ampersand Substitution Variables 7Ć9 Defining User Variables 7Ć15 Passing Values into a Script File 7Ć21 Summary 7Ć23 Practice Overview 7Ć25 Practice 7 7Ć26
8 Overview of Data Modeling and Database Design 8Ć1
Trang 69 Creating Tables 9Ć1 Objectives 9Ć3 Overview 9Ć5 Creating Tables 9Ć7 Oracle7 Datatypes 9Ć13 Constraints 9Ć15 Creating a Table from a Table Instance Chart 9Ć25 Creating a Table from Rows in Another Table 9Ć31 Confirming Table Creation 9Ć33 Summary 9Ć35 Practice Overview 9Ć37 Practice 9 9Ć39
10 Oracle Data Dictionary 10Ć1 Objectives 10Ć3 Overview 10Ć5 Querying the Data Dictionary 10Ć7 Checking Constraints on a Table 10Ć13 Summary 10Ć17 Practice Overview 10Ć19 Practice 10 10Ć21
11 Manipulating Data 11Ć1 Objectives 11Ć3 Overview 11Ć5 Adding a New Row to a Table 11Ć7 Copying Rows from Another Table 11Ć19 Updating Rows 11Ć21 Deleting Rows 11Ć29 Transaction Processing 11Ć35 Committing Changes 11Ć39 Rolling Back Changes 11Ć43 Rolling Back Changes to a Savepoint 11Ć45 Statement Level Rollback 11Ć47 Summary 11Ć49 Practice Overview 11Ć51 Practice 11 11Ć53
12 Altering Tables and Constraints 12Ć1 Objectives 12Ć3 Overview 12Ć5 Adding a Column 12Ć7 Modifying a Column 12Ć9 Adding and Dropping a Constraint 12Ć11
Trang 7Disabling and Enabling a Constraint 12Ć15 Dropping a Table 12Ć17 Renaming and Truncating a Table 12Ć19 Adding a Comment to a Table 12Ć21 Summary 12Ć23 Practice Overview 12Ć25 Practice 12 12Ć27
13 Creating Sequences 13Ć1 Objectives 13Ć3 Overview 13Ć5 Creating a Sequence 13Ć7 Using a Sequence 13Ć13 Altering a Sequence 13Ć17 Removing a Sequence 13Ć19 Summary 13Ć21 Practice Overview 13Ć23 Practice 13 13Ć25
14 Creating Views 14Ć1 Objectives 14Ć3 Overview 14Ć5 Creating a View 14Ć7 Performing DML Operations on a View 14Ć15 Confirming View Names and Structures 14Ć21 Removing a View 14Ć23 Summary 14Ć25 Practice Overview 14Ć27 Practice 14 14Ć29
15 Creating Indexes 15Ć1 Objectives 15Ć3 Overview 15Ć5 When Is the Index Used? 15Ć7 Index Structure 15Ć9
Trang 8System Privileges 16Ć7 What Is a Role? 16Ć11 Changing Your Password 16Ć13 Granting Object Privileges 16Ć15 Confirming Privileges Granted 16Ć21 Revoking Object Privileges 16Ć23 Creating a Synonym for an Object 16Ć25 Summary 16Ć29 Practice Overview 16Ć31 Practice 16 16Ć33
17 Summary of SQL and SQL*Plus 17Ć1 Summary of SQL and SQL*Plus 17Ć3 Practice Overview 17Ć9 Practice 17 17Ć11Volume 3
18 Overview of PL/SQL 18Ć1 Objectives 18Ć3 Overview 18Ć5 PL/SQL Block Structure 18Ć9 The PL/SQL Environment 18Ć15 About Procedure Builder 18Ć17
19 Basics of Procedure Builder 19Ć1 Objectives 19Ć3 Overview 19Ć5 Oracle Procedure Builder Capabilities 19Ć7 Procedure Builder Components 19Ć9 The Object Navigator 19Ć15 The Interpreter 19Ć23 The Program Unit Editor 19Ć27 The Stored Program Unit Editor 19Ć31 Debugging a Stored Program Unit 19Ć33 Performing Debug Actions in the Interpreter 19Ć35 Setting a Breakpoint 19Ć37 Examining Local Variables 19Ć43 Summary 19Ć45 Practice Overview 19Ć47 Practice 19 19Ć49
20 Modularizing Programming with Subprograms 20Ć1 Objectives 20Ć3 Overview 20Ć5
Trang 9Creating a Subprogram 20Ć7 Creating a Procedure 20Ć9 Comparing Functions and Procedures 20Ć15 Creating a Function 20Ć17 Invoking Subprograms 20Ć21 Summary 20Ć29 Practice Overview 20Ć31 Practice 20 20Ć33
21 Developing a Simple PL/SQL Block 21Ć1 Objectives 21Ć3 Overview 21Ć5 Declaring PL/SQL Variables and Constants 21Ć7 Declaring Scalar Variables 21Ć9 Declaring Composite Datatypes 21Ć15 PL/SQL Block Syntax Rules 21Ć25 Assigning Values to Variables 21Ć29 Programming Guidelines 21Ć43 Summary 21Ć49 Practice Overview 21Ć51 Practice 21 21Ć53
22 Interacting with Oracle 22Ć1 Objectives 22Ć3 Overview 22Ć5 Retrieving Data Using PL/SQL 22Ć7 SELECT Exceptions 22Ć15 Manipulating Data Using PL/SQL 22Ć19 SQL Cursor 22Ć23 Controlling Transactions 22Ć27 Summary 22Ć31 Practice Overview 22Ć33 Practice 22 22Ć35
23 Controlling Flow in PL/SQL Blocks 23Ć1
Trang 1024 Processing Queries by Using Explicit Cursors 24Ć1 Objectives 24Ć3 Overview 24Ć5 Controlling Explicit Cursors 24Ć7 Explicit Cursor Attributes 24Ć17 Cursors and Records 24Ć21 Cursors with Parameters 24Ć23 Cursor FOR Loops 24Ć25 Applying the WHERE CURRENT OF Clause 24Ć27 Summary 24Ć29 Practice Overview 24Ć31 Practice 24 24Ć33
25 Error Handling 25Ć1 Objectives 25Ć3 Overview 25Ć5 Exception Types 25Ć7 Trapping Exceptions 25Ć9 Trapping Predefined Oracle7 Server Exceptions 25Ć11 Trapping NonĆPredefined Oracle7 Server Exceptions 25Ć15 Trapping UserĆDefined Exceptions 25Ć17 Error Trapping Functions 25Ć19 Propagating Exceptions 25Ć21 Summary 25Ć23 Practice Overview 25Ć25 Practice 25 25Ć27
26 Summary of PL/SQL 26Ć1 Summary 26Ć3 Practice Overview 26Ć9 Practice 26 26Ć11Volume 4
A Practice Solutions AĆ1 Preface AĆ3 Practice 1 Solutions AĆ4 Practice 2 Solutions AĆ8 Practice 3 Solutions AĆ20 Practice 4 Solutions AĆ29 Practice 5 Solutions AĆ39 Practice 6 Solutions AĆ46 Practice 7 Solutions AĆ55 Practice 9 Solutions AĆ59 Practice 10 Solutions AĆ63
Trang 11Practice 11 Solutions AĆ68 Practice 12 Solutions AĆ82 Practice 13 Solutions AĆ88 Practice 14 Solutions AĆ97 Practice 15 Solutions AĆ105 Practice 16 Solutions AĆ109 Practice 17 Solutions AĆ116 Practice 19 Solutions AĆ154 Practice 20 Solutions AĆ155 Practice 21 Solutions AĆ158 Practice 22 Solutions AĆ163 Practice 23 Solutions AĆ170 Practice 24 Solutions AĆ177 Practice 25 Solutions AĆ186 Practice 26 Solutions AĆ192
B Table Descriptions and Data BĆ1 Summit Sporting Goods Database Diagram BĆ3 S_CUSTOMER Table BĆ4 S_DEPT Table BĆ7 S_EMP Table BĆ8 S_IMAGE Table BĆ10 S_INVENTORY Table BĆ11 S_ITEM Table BĆ16 S_ORDTable BĆ20 S_PRODUCT Table BĆ22 S_REGION Table BĆ25 S_WAREHOUSE Table BĆ26
C Using SQL*Plus to Create Reports and Manage PL/SQL Code CĆ1 Objectives CĆ3 Overview CĆ5 Entering Commands in SQL*Plus CĆ7 Comparison of SQL and SQL*Plus Commands CĆ9
Trang 12Practice C CĆ45 Practice C Solutions CĆ47
D Related Products and Services DĆ1 Related Products DĆ3 Related Services DĆ5 Glossary
Index
Trang 13Preface
Trang 14Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xiv
Profile
Before You Begin This Course
Before you begin this course, you should be able to use a graphical user interface(GUI) Required prerequisites are familiarity with data processing concepts andtechniques
HowThis Course Is Organized
Introduction to Oracle: SQL and PL/SQL Using Procedure Builder is an
instructor-led course featuring lecture and hands-on exercises The concepts and skillsintroduced are reinforced by online demonstrations and written practice sessions.HowThis Book Is Organized
Lesson 1: Selecting Rows In order to extract data from the database
you need to use the Structured QueryLanguage (SQL) SELECT command You will want to create SELECTstatements that you can use time andtime again You will also see how to saveyour statements for later use
Lesson 2: Limiting Selected Rows This lesson will cover how to restrict the
rows and columns that are displayed, aswell as how to specify the order in whichthe rows are presented
Trang 15Profile continued
Lesson 3: Single Row Functions Functions make the basic query block
more powerful and are used tomanipulate data values This is the first
of two lessons that explore functions.You will focus on single row character,number, and date functions, as well asthose functions that convert data fromone type to another, for example,character data to numeric
Lesson 4: Displaying Data from Multiple
Tables
This lesson will cover how to obtain datafrom more than one table, using themany different methods available
Lesson 5: Group Functions This lesson further addresses functions
You will focus on obtaining summaryinformation, such as averages, for groups
of rows You will discuss how to grouprows in a table into smaller sets, and how
to specify search criteria for groups ofrows
Lesson 6: Subqueries This lesson covers more advanced
features of the SELECT statement Youcan write subqueries in the WHEREclause of another SQL statement toobtain values based on an unknownconditional value
Lesson 7: Specifying Variables at
Runtime
You can create a command filecontaining a WHERE clause to restrictthe rows displayed To change thecondition each time the command file isrun, you use substitution variables
Trang 16Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xvi
Lesson 8: Overview of Data Modeling
and Database Design
Before you build your tables, you designyour database You examine the datamodeling process and relational databaseconcepts, and define normalization Youalso translate an entity relationshipmodel into a relational database design.Lesson 9: Creating Tables You will create tables You will also
build integrity constraints, which arerules governing what can and cannot bedone with the data
Lesson 10: Oracle Data Dictionary The Oracle data dictionary is one of the
most important components of theOracle7 Server It consists of a set oftables and views that provide a read-onlyreference to the database
Lesson 11: Manipulating Data Once your tables have been created, you
will need to add new rows, makechanges to rows in a table, or delete rows
by using data manipulation commands.This lesson covers using SQL commands
to make changes to data A number ofthese data manipulation commands make
up a transaction, which you may eithersave or delete using transaction controls.Lesson 12: Altering Tables and
Constraints
After you create your tables, you mayneed to change the table structuresbecause you omitted a column, yourcolumn definition needs to be changed,
or you want to enable or disableconstraints This lesson will demonstratehow you can amend table structures aswell as add and remove constraints
Trang 17Profile continued
Lesson 13: Creating Sequences Many applications require the use of
unique numbers as primary key values.You can either build code into theapplication to handle this requirement oruse a sequence to generate uniquenumbers This lesson covers creating andusing sequences that crate unique
numbers
Lesson 14: Creating Views In this lesson, you will see how views
can be used to present data to users in avariety of ways In addition, you will seehow integrity constraints can be
enforced, if using a view to insert,update, or delete data
Lesson 15: Creating Indexes If you want to improve the performance
of some queries, you should considercreating an index You can also useindexes to enforce uniqueness on acolumn or a collection of columns
Lesson 16: Controlling User Access This lesson describes the Oracle7 Server
decentralized security system Using thecommands covered in this lesson, youcan control database access to specificobjects and add new users with differentlevels of access privileges You canprovide alternative names for objects byusing the CREATE SYNONYM
command
Trang 18Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xviii
Lesson 18: Overview of PL/SQL Overview lesson of how to create and
use PL/SQL program units andsubprograms using Oracle ProcedureBuilder
Lesson 19: Basics of Procedure Builder A key feature of procedural
programming is the ability to create anddebug code quickly and easily
Procedure Builder provides all of thefunctionality necessary for you tosuccessfully develop and debug PL/SQLprograms This lesson enables you tomanipulate PL/SQL code usingProcedure Builder
Lesson 20: Modularizing Programming
with Subprograms
Modularity allows you to break yourcode into manageable, well-definedunits Each of these units in PL/SQL hastwo types of subprograms called
procedures and functions You will learnthe structure of subprograms and how toinvoke them
Lesson 21: Developing a Simple
PL/SQL Block
Create a simple PL/SQL block afterlearning the various elements thatcompose a block
Lesson 22: Interacting with Oracle Access the database and control
transactions through SQL statements inPL/SQL
Trang 19Profile continued
Lesson 23: Using Control Structures Control the flow of your PL/SQL block
by using conditional statements andloops
Lesson 24: Processing Queries with
Explicit Cursors
Use a multiple row SELECT statementwithin PL/SQL to process many rows.Declare and control explicit cursors,which are used in loops, including thecursor FOR loop
Lesson 25: Error Handling When you execute PL/SQL code, you
may encounter errors The error causesthe PL/SQL block to halt with anexception You can trap the exceptionand perform actions conditionally usingexception handlers
Lesson 26: Summary of PL/SQL
(optional)
Review the topics covered in the course.Create a PL/SQL-based application formanipulating and maintaining
information in your database
Trang 20Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xx
Related Publications
Oracle Publications
Oracle7 Server SQL Reference, Release 7.3 A32538
SQL*Plus User’s Guide and Reference, Release 3.3 A42562–1
PL/SQL User’s Guide and Reference, Release 2.3 A32542
Oracle7 Server SQL Language Quick Reference 5421–70–1292
SQL*Plus Quick Reference, Release 3.3 A42561
Oracle Procedure Builder 1.5 Developer’s Guide A32485
Oracle7 Server Concepts Manual, Release 7.3 A32534
Oracle Press: Oracle Beginner’s Guide A31178–1
Oracle Press: Oracle Complete Reference A10197–1
Additional References
D System Release Bulletins
D Installation and User’s Guides
D read.me Files
D International Oracle User’s Group (IOUG) Articles
D Oracle Magazine
Trang 21Typographic Conventions
Typographic Conventions Within Text
Convention Object or Term Example
Uppercase Commands,
functions,column names,table names,PL/SQL objects,schemas
Use the SELECT command to viewinformation stored in the LAST_NAMEcolumn of the S_EMP table
Lowercase,
italic
File names,syntax variables,usernames,passwords
where: role is the name of the role to be
Press the Cancel button
Italic Books, names of
courses andmanuals, andemphasizedwords or phrases
For further information on the subject see:
Oracle7 Server SQL Language Reference Manual
Do not save changes to the database.
Quotation marks Lesson module
titles referencedwithin a course
This subject is covered in Lesson 3, “Workingwith Objects.”
Italic bold The first time a
glossary word isreferred to in asection
The algorithm inserts the new key.
Trang 22Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xxii
Typographic Conventions Within Code
Convention Object or Term Example
Syntax variables SQL> CREATE ROLE role;
Lowercase Column names,
table names, filenames, PL/SQLobjects
OG_ACTIVATE_LAYER (OG_GET_LAYER (’prod_pie_layer’))
SQL> SELECT userid
Vertical bar Separates
alternativesyntax elements
{OFF | ON}
Underlining Default value in
syntax
{OFF | ON}
Trang 23Typographic Conventions continuedSymbols Used in This Document
Guidance relating to the subject matter, such as hints or advice
For more information, see
a publication related to the subject matter
This icon indicates a warning relating to the subject matter An example warningmight be “When deleting rows, word your WHERE clause carefully.”
Used for a series of instructions that must be followed in sequential order
Trang 24Introduction to Oracle: SQL and PL/SQL Using Procedure Builder xxiv
Trang 25I
Trang 26Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ2
Trang 27Course Objectives
At the end of this course, you should be able to
D Describe the relational database approach, concepts, terminology, and operators
D Create database structures such as tables and views using Structured QueryLanguage (SQL)
D Store, retrieve, and update data in the database
D Develop PL/SQL blocks of application code using Procedure Builder to
manipulate data
Trang 28Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ4
Trang 29Course Outline
The course starts with an overview The first module ends on Day 3 with an optional summary covering the SQL and SQL*Plus content The second module ends on Day 5 with an optional summary of the PL/SQL section.
DAY 1
Lesson 1 Selecting Rows
Lesson 2 Limiting Selected Rows
Lesson 3 Single Row Functions
Lesson 4 Displaying Data from Multiple Tables
DAY 2
Lesson 5 Group Functions
Lesson 6 Subqueries
Lesson 7 Specifying Variables at Runtime
Lesson 8 Overview of Data Modeling and Database Design
Lesson 9 Creating Tables
Lesson 10 Oracle Data Dictionary
DAY 3
Lesson 11 Manipulating Data
Lesson 12 Altering Tables and Constraints
Lesson 13 Creating Sequences
Lesson 14 Creating Views
Lesson 15 Creating Indexes
Lesson 16 Controlling User Access
Lesson 17 Summary of SQL and SQL*Plus
Trang 30Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ6
Trang 31Course Outline continued
DAY 4
Lesson 18 Overview of PL/SQL
Lesson 19 Basics of Procedure Builder
Lesson 20 Modularizing Programming with Subprograms
Lesson 21 Developing a Simple PL/SQL Block
Lesson 22 Interacting with Oracle
DAY 5
Lesson 23 Controlling Flow in PL/SQL Blocks
Lesson 24 Processing Queries by Using Explicit Cursors
Lesson 25 Error Handling
Lesson 26 Summary of PL/SQL
(optional)
Trang 32Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ8
Trang 33The Relational Database Concept
The principles of the relational model were first outlined by Dr E F Codd in a June
1970 paper called “A Relational Model of Data for Large Shared Data Banks.” In thispaper, Dr Codd proposed the relational model for database systems
The more popular models used at that time were hierarchical and network, or even
simple flat file data structures Relational database management systems (RDBMS)
soon became very popular, especially for their ease of use and flexibility in structure
In addition, there were a number of innovative vendors, such as Oracle, who
supplemented the RDBMS with a suite of powerful application development and userproducts, providing a total solution
Concepts of the Relational Model
D Collections of objects or relations store the data
D A set of operators can act on the relations to produce other relations
D A relational database must possess data integrity so that its data must be accurateand consistent
An example of a relation is a table To retrieve data from the tables, use relationaloperation SQL commands
Relational Database Functions
D Manage the storage of data
D Control access to the data
D Provide a means to retrieve and modify the data
For more information, see
The Relational Model for Database Management Version 2, E F Codd, Addison
Wesley
Trang 34Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ10
Trang 35The Relational Database Concept continuedDatabase Terminology
Concept Description
Table A table is the basic storage structure of an RDBMS, consisting
of one or more columns and zero or more rows
Row A row is a combination of column values in a table; for
example, the information about one department in the tableS_DEPT A row is sometimes called a “record”
Column A column represents one kind of data in a table; for example,
the department name in the example table S_DEPT It isdescribed with a column name and holds data of a specific typeand size
Field At the intersection of a row and a column, you find a field The
field can contain data If there is no data in the field, it is said tocontain a null value
Primary Key A primary key is the column or set of columns that uniquely
identifies each row in a table; for example a departmentnumber It must contain a value
Foreign Key A foreign key is a column or set of columns that refers to a
primary key in the same table or in another table You createthem to enforce relational database design rules
Guidelines
D No duplicate values are allowed in a primary key
D Primary keys generally cannot be changed
D Foreign keys are based on data values and are purely logical, not physical
pointers
D A foreign key value must match an existing primary key value or else be NULL
Trang 36Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ12
Trang 37The Relational Database Concept continuedRelational Database Properties
A database is a collection of individual, named objects, such as tables You do notspecify the access route to the tables, and do not need to know how the data is
arranged physically
To access the database, you execute a Structured Query Language (SQL) command,
which is the American National Standards Institute (ANSI) standard language foroperating upon relational databases The language contains a large set of operators forpartitioning and combining relations The database can be easily modified by usingthe SQL commands The relational model allows for full data independence
Abridged List of Database Objects
Object Description
Table Basic unit of storage composed of rows and columns
View Logically represents subsets of data from one or more tables
Sequence Generates primary key values
Index Improves the performance of queries
Synonym Alternate name for an object
Program unit Procedure, function, or package of SQL and PL/SQL statements
grouped together
Table Properties
A single table is composed of rows and columns The intersection of the rows andcolumns are the field values Each row should be identified by a primary key, whichallows no duplicate rows The order of the rows is insignificant; by default, the data isordered in the order in which it was inserted Each column is uniquely named
Column order is insignificant when storing data; specify the column order when thedata is retrieved Field values cannot be broken into smaller components
Trang 38Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ14
Trang 39The Relational Database Concept continuedProtect Data Integrity
Ensure that users perform only operations that leave the database in a correct andconsistent state with data integrity constraints All data integrity constraints should beenforced by the database server or the application software
Integrity Constraint Type Description
Entity No part of a primary key can be NULL and the
value must be unique
Referential Foreign key values must match a primary key or be
Trang 40Introduction to Oracle: SQL and PL/SQL Using Procedure Builder IĆ16