You are on page 1of 32

I

Introduction
Relational and Object Relational
Database Management Systems
• Relational model and object relational model
• User-defined data types and objects
• Fully compatible with relational database
• Supports multimedia and large objects
• High-quality database server features

I-2
Data Storage on Different Media

Electronic
Filing cabinet Database
spreadsheet

I-3
Relational Database Concept

• Dr. E. F. Codd proposed the relational model for database


systems in 1970.
• It is the basis for the relational database management
system (RDBMS).
• The relational model consists of the following:
– Collection of objects or relations
– Set of operators to act on the relations
– Data integrity for accuracy and consistency

I-4
Definition of a Relational Database

A relational database is a collection of relations or


two-dimensional tables.

Oracle
server

Table name: EMPLOYEES Table name: DEPARTMENTS

… …

I-5
Data Models

Model of
Entity model of
system
client’s model
in client’s
mind
Table model
of entity model Oracle
server

Tables on disk

I-6
Entity Relationship Model

• Create an entity relationship diagram from business


specifications or narratives:

EMPLOYEE DEPARTMENT
assigned to
#* number #* number
* name * name
o job title composed of o location

• Scenario:
– “. . . Assign one or more employees to a
department . . .”
– “. . . Some departments do not yet have assigned employees
. . .”

I-7
Entity Relationship
Modeling Conventions
Entity: Attribute:
• Singular, unique name • Singular name
• Uppercase • Lowercase
• Mandatory marked with “*”
• Soft box • Optional marked with “o”
• Synonym in parentheses

EMPLOYEE DEPARTMENT
#* number assigned to
#* number
* name * name
o job title composed of o location

Unique Identifier (UID)


Primary marked with “#”
Secondary marked with “(#)”

I-8
Relating Multiple Tables

• Each row of data in a table is uniquely identified by a primary


key.
• You can logically relate data from multiple tables using
foreign keys.
Table name: DEPARTMENTS

Table name: EMPLOYEES


Primary key Foreign key Primary key

I-9
Relational Database Terminology
3
2 4

I - 10
Architecture

I - 11
Logical & Physical Structure

I - 12
Logical & Physical Structure

I - 13
Using SQL to Query Your Database

Structured query language (SQL) is:


• The ANSI standard language for operating relational
databases
• Efficient, easy to learn, and use
• Functionally complete (With SQL, you can define, retrieve,
and manipulate data in the tables.)
SELECT department_name
FROM departments;
Oracle
server

I - 14
SQL Statements

SELECT
INSERT
UPDATE Data manipulation language (DML)
DELETE
MERGE

CREATE
ALTER
DROP Data definition language (DDL)
RENAME
TRUNCATE
COMMENT

GRANT Data control language (DCL)


REVOKE

COMMIT
ROLLBACK Transaction control
SAVEPOINT

I - 15
Development Environments for SQL

In this course:
• Primarily use Oracle SQL Developer
• Use SQL*Plus:
– In case you do not have access to Oracle SQL Developer
– Or when any command does not work in Oracle SQL
Developer

SQL Developer SQL *Plus

I - 16
What Is Oracle SQL Developer?

• Oracle SQL Developer is a graphical tool that enhances


productivity and simplifies database development tasks.
• You can connect to any target Oracle database schema by
using the standard Oracle database authentication.

SQL Developer

I - 17
Specifications of Oracle SQL Developer

• Developed in Java
• Supports Windows, Linux, and Mac OS X platforms
• Default connectivity by using the JDBC Thin driver
• Does not require an installer
– Unzip the downloaded Oracle SQL Developer kit and double-
click sqldeveloper.exe to start Oracle SQL Developer.
• Connects to any Oracle Database, version 9.2.0.1 and later
• Freely downloadable from the following link:
– http://www.oracle.com/technology/products/database/
sql_developer/index.html
• Needs JDK 1.5 installed on your system, which can be
downloaded from the following link:
– http://java.sun.com/javase/downloads/index_jdk5.jsp

I - 18
Oracle SQL Developer Interface

You must define a


connection to start
using SQL Developer
for running SQL queries
on a database schema.

I - 19
Creating a Database Connection

• You must have at least one database connection to use


Oracle SQL Developer.
• You can create and test connections for:
– Multiple databases
– Multiple schemas
• Oracle SQL Developer automatically imports any
connections defined in the tnsnames.ora file on your
system.
• You can export connections to an XML file.
• Each additional database connection created is listed in the
Connections Navigator hierarchy.

I - 20
Creating a Database Connection
1

I - 21
Browsing Database Objects

Use the Connections Navigator to:


• Browse through many objects in a database schema
• Review the definitions of objects at a glance

I - 22
Using the SQL Worksheet

• Use the SQL Worksheet to enter and execute SQL, PL/SQL,


and SQL*Plus statements.
• Specify any actions that can be processed by the database
connection associated with the Worksheet.

Enter SQL
Statements.

Results are
shown here.

I - 23
Using the SQL Worksheet

1 2 4 6 8 9

5 7
3

I - 24
Executing SQL Statements

Use the Enter SQL Statement box to enter single or multiple


SQL statements.

F9 F5

F5
F9

I - 25
Formatting the SQL Code

Before
formatting

After
formatting

I - 26
Saving SQL Statements

2
3

I - 27
Running Script Files

I - 28
Starting SQL*Plus from Oracle SQL Developer

You can invoke the SQL*Plus command-line interface from


Oracle SQL Developer.

Provide the
location of the
sqlplus.exe
file only for
the first time
you invoke
SQL*Plus.

I - 29
SQL Statements in SQL*Plus

In Oracle Database 11g, SQL*Plus is a command-line interface.

I - 30
The Human Resources (HR)Schema

DEPARTMENTS LOCATIONS
department_id location_id
department_name street_address
manager_id postal_code
location_id city
state_province
country_id
JOB_HISTORY
employee_id
start_date EMPLOYEES
employee_id
end_date
first_name
job_id
last_name COUNTRIES
department_id
email country_id
phone_number country_name
hire_date region_id
job_id
salary
commission_pct
JOBS manager_id
job_id department_id
job_title
min_salary
REGIONS
max_salary region_id
region_name

I - 31
Tables Used in the Course

EMPLOYEES

DEPARTMENTS JOB_GRADES

I - 32

You might also like