Uploaded by Ahmad Alqerem

oracle database introduction

advertisement
Advance Database
Introduction
Course Description
This course is designed to provide students with theoretical knowledge and practical skills in advanced topics in
database systems.
• Advance SQL and Analytical SQL
• Indexing methods
• Performance optimization - Tuning Hints
• Query processing and optimization strategies for a relational database.
• Object Relational Mapping
• Distributed database systems
• Data mining on large databases.
Tools
1. Oracle XE 12c:
• https://www.oracle.com/database/technologies/xe-downloads.html
2. Oracle Data Modeler tool (need Oracle user)
https://www.oracle.com/database/sqldeveloper/technologies/sql-data-modeler/download/
https://drive.google.com/file/d/1FUyFSlMwkVaCC51DADh0icW5jxe4-U1O/view?usp=sharing
3. SQL Navigator
https://drive.google.com/file/d/18jYnvWCYEABZNONGGk64RtRkkDeTxhI7/vi
ew?usp=sharing
4. Data Visualization
Introduction
Objectives
Review
• DB Concepts: Database, database management system, OLAP, OLTP,
Row Storge, column storage.
• Database objects type.
• DB Reverse Engineering Process.
• DBMS Language.
• Normalized and denormalized Database.
Database Management Systems
• Database
• A collection of data, typically describing the activities of one or more related organizations.
For example, a university database might contain information about the following:
Entities such as students, faculty, courses, and classrooms.
Relationships between entities, such as students' enrollment in courses, faculty teaching courses, and the use
of rooms for courses.
• Database Management System – DBMS
Software designed to assist in maintaining and utilizing large collections of data, and the need for such systems,
as well as their use, is growing rapidly.
Network Architecture
Network Architecture
Highlights Before Database Installation
How to install a database in an organization (Simple Installation
for light application)?
1.Select a Database Management System that fits
Organization’s needs.
2.Look at the required specification
3. Download the installation file
4.Choose the Database type (OLAP, OLTP) **
5.Follow the guide based on the selected installation topology
Database Tools
Examples Database Tools
• SQL Navigator
Examples Database Tools
• Data Modeling Tools
Examples Database Tools
• SQL Plus
Lab
Installing Oracle Database
Database Objects
Database Objects
• Any defined object in the database which can be used to reference or
store data is known as a database object.
• Database objects can be made using the create command.
• These database objects are used for holding and manipulating the
data in the database.
Database Objects
• Table: logical structures maintained by the database manager and are
made up of columns and rows.
• Constraints: certain restrictions or rules applied to data.
• Index: An index is a set of pointers that are logically ordered by the
values of one or more keys.
• Triggers: A trigger
• Defines a set of actions that are performed in response to an insert, update,
or delete operation on a specified table.
• When such an SQL operation is executed, the trigger is said to have
been activated. Triggers are optional and are defined using the CREATE
TRIGGER statement.
Database Objects
• Sequences: a database object that allows the automatic generation of
values.
• Sequences are ideally suited to the task of generating unique key values.
• It is used to avoid possible concurrency and performance problems resulting
from column values used to track numbers.
• A crash and restart will not cause duplicate numbers from being generated.
• View : "virtual table“, is an efficient way of representing data without
the need to maintain it. A view is not an actual table and requires no
permanent storage.
Database Objects
• In Oracle DB:
Table
Table
Indexes
Constraints
Trigger
Trigger
Views
Views
Sequences
NEXTVAL: Increment the sequence and
return the result value
CURRVAL: return the last sequence value
Reverse Engineering
Reverse Engineering
Reverse Engineering
• Reverse engineering is the process of creating a data model from a
database or a script.
• The modeling tool creates a graphical representation of the selected
database objects and the relationships between the objects.
• This graphical representation can be a logical or a physical model.
Reverse Engineering Reasons
• A database can be reverse-engineered for the following reasons:
• To understand how the objects are related to each other and then to build
upon it
• To demonstrate the database structure
• After the reverse engineering process completes, you can perform the
following tasks:
• Add new database objects
• Create the system documentation
• Redesign the database structure to suit your requirements
Reverse Engineering
Edit
Reverse
Engineered
Generate
Script
Generate
Doc
Demo
Reverse Engineering
DBMS Language
• Database languages, also known as query languages or data query
languages, are a classification of programming languages that
developers use to define and access databases
Four categories of database languages
•
•
•
•
Data definition language (DDL)
Data manipulation language (DML)
Data control language (DCL)
Transaction control language (TCL)
Data Definition Language (DDL)
• DDL Statements: Creates the framework of the database by specifying
the database
• Its common uses include the creation and alteration of tables, files,
indexes, and columns within the database.
• Common DDL statements:
•
•
•
•
CREATE: Creates a new database or object, such as a table, index, or column
ALTER: Changes the structure of the database or object
DROP: Deletes the database or existing objects
RENAME: Renames the database or existing objects
Create SQL Statement
DDL Example
Empty Database
Refresh Database to View
the table
Data Manipulation Language (DML)
• DML Statements: Access and manipulate the data that users store
within a database.
• Its common functions include the following:
•
•
•
•
INSERT: Adds new data to the existing database table
UPDATE: Changes or updates values in the table
DELETE: Removes records or rows from the table
SELECT: Retrieves data from the table or multiple tables
DML Example
What Happens if the Electricity cutouts after executing this statement?
Transaction Control Language (TCL)
• TCL statement manages the transactions within a database.
• Transactions group a set of related tasks into a single, executable task
(Logical Transaction).
• All the tasks must succeed in order for the transaction to work.
• Its common functions include the following:
• COMMIT: Carries out a transaction
• ROLLBACK: Restores a transaction if any tasks fail to execute.
• SAVEPOINT: command is used to temporarily save a transaction so that you
can rollback to that point whenever necessary.
TCL Example1
One Logical
Transaction
2 Rows Inserted
One Logical
Transaction
0 Rows Inserted
Step1
TCL Example2
One Logical Transaction
2 Rows Inserted
Data Control Language (DCL)
• DCL Statement controls access to the data that users store
within a database.
• Essentially, this language controls the rights and
permissions of the database system.
• It allows users to grant or revoke privileges to the
database.
• Its common functions include the following:
• GRANT: Gives a user access to the database
• REVOKE: Removes a user's access to the database
DCL Example
Assessment
• The following statement is:
a)
b)
c)
d)
Data definition language (DDL)
Data manipulation language (DML)
Data control language (DCL)
Transaction control language (TCL)
Assessment
• The following statement is:
a)
b)
c)
d)
e)
Data definition language (DDL)
Data manipulation language (DML)
Data control language (DCL)
Transaction control language (TCL)
This is not a statement.
Assessment
• What is the result of the select statement after
executing the script?
A.
B.
C.
D.
Table contains No rows.
The table contains two rows
The table contains one row.
The table contains two rows and the first one is
updated.
Constraints & relationships
Normalized vs Denormalized Database
Normalization
• The method used in a database to reduce the data redundancy and
data inconsistency from the table.
• It involves constructing tables and setting up relationships between
those tables according to a set of certain rules.
• Normalization is used in OLTP system, which emphasizes on making
the insert, delete and update anomalies faster.
Normalized vs Denormalized Database
Denormalization
• The process of taking a normalized schema and making it nonnormalized
• It is used to tune and improve the performance of systems to support
time-critical fetch operations.
• Updates and inserts (DML operation) are more expensive.
• Data may be inconsistent.
• Data redundancy consumes more storage.
Normalized vs Denormalized Database
Normalized
Denormalized
Assessment
• By using normalization the number of tables is increased instead of
decreased.
A. True
B. False
• Normalization optimizes the uses of disk spaces.
A. True
B. False
Assessment
• Denormalization data model is no longer used
A. True
B. False
• It is used in data warehouse to optimize data retrieval
Lab - Sample Schemas
Lab - Reverse Engineering Lab
Download