Professional Documents
Culture Documents
Oracle Course
Oracle Course
Table of contents
What is a database?
Fundamentals of database
Table management
Inserting data
Updating data
Deleting data
Query management
Simple queries
Aggregate functions
String manipulation
Date manipulation
Sub queries
Equi join
Outer join
Self join
Union, intersection, minus
View management
Sequence Management
Index Management
Constraints Management
Triggers
Stored procedures
Exceptions
Sequences
Constraints
DBA features
Softsmith Infotech
Fundamentals of database
Applications are used by end users and they enter a
group of raw data
This data is later collated and used by management to
arrive at meaningful information
Before we first understand the technical aspects of
database, we must understand the business data clearly
Rule 1: In any application, first identify raw data
Rule 2: Group related data and associate data type and
size (summary and detail)
Rule 3: Create a set of samples for each of these groups
for better clarity
Rule 4: Identify unique and non-unique data
Rule 5: Identify the relationship between the data
Softsmith Infotech
Passenger name
Age
Date of journey
Train name
From station
To Station
PNR number
Route codes
Stations covered in the route
Components of database
A physical database installation in a machine
has the following logical entities
Softsmith Infotech
Table Management
Softsmith Infotech
Inserting Data
INSERT operation into a table requires data to
be entered
We can insert all column values or selective
column values
When insert is successful, we will get a success
message
When we try to enter a duplicate value into a
table, we will get duplicate constraint violation
message
During insert, if we do not supply a value, the
default value for a column is used to fill up that
column
We can insert data only to one table at a time
Softsmith Infotech
Update Operation
When we want to modify data in a table, we can use
UPDATE command
We can update only one table at a time
When we update we need to use the SET clause to set
the values for a particular column
During update also, if try to update a record, such that it
results in duplicate record, we will get a unique constraint
violation message
If we use update command without WHERE clause, it will
update all the records
It is not recommended to update, without giving a where
clause
Examples
Update employee set salary = 1000
Update employee set salary = 2000 where designation =
SALESMANAGER
Softsmith Infotech
Delete Operation
When we want to remove data in a table, we can
use DELETE command
We can delete only one table at a time
We cannot delete a particular column; it is
always one row or multiple rows
If we use delete command without WHERE
clause, it will delete all the records
It is not recommended to delete, without giving a
where clause
Example
delete from employee
Delete from employee where designation =
HRMANAGER
Softsmith Infotech
SELECT Queries
When we want to retrieve data from a table, we
use SELECT clause
Most of the times, testers use SELECT queries
only
SELECT has a lot of variations and clauses.
Hence SELECT is a must for all testers
SELECT queries can handle date and string
manipulation commands as well
SELECT helps to filter, search and sort data
SELECT helps to find out relationships in data
Softsmith Infotech
Simple query
SELECT * from TRAINS
this will get all columns in the table
Aggregate functions
Aggregate functions work on the whole set of
records
SELECT max(salary) from EMPLOYEE
this will get the maximum salary data from the table
Softsmith Infotech
Operators
We can use arithmetic operators like +, -, *, /
Logical operators are AND, OR, NOT
Open and close brackets are used to group
items
% is used along with LIKE operator
Where firstname LIKE %raj% will search for raj
anywhere in firstname column
Distinct is an operator on a column to fetch
distinct values present in all rows
IN operator is used to provide a set of values in
the WHERE clause
BETWEEN operator is used to provide a range
of values in the WHERE clause
Softsmith Infotech
SubQuery
Sub query is query within a query
This is used to ensure that the WHERE condition is
further getting values from another query
Select employee_name, salary from employee where
designation = (select designation from positionmaster
where positioncategory like %MANAGER%)
The innermost select is executed first and then the outer
select is executed
In sub queries, if we use = in where condition, the
subquery must return only one value
In sub queries, if we use IN clause in where condition,
the subquery can return more than one values
Softsmith Infotech
JOINs
Joins are nothing but a cross product of one or
more tables
Inner join is used to get records that match a
condition in all tables
In joins we use alias to denote table names
Outer join is used to get records from more than
one tables, irrespective of the condition match in
left or right table
Example
SELECT a.empname, b.projectname from employees
a, projects b where a.employeecode =
b.employeecode and b.projectstatus = Active
Views
A view is a virtual table
A view is used to simplify a complex select
statement
A view can bring multiple data from many tables
For all query purposes, a view is treated as a
table
Create View SalesPeople As Select
employeename from employees where
designation like %SALES%
When we create views, our job to write complex
queries get reduced
Softsmith Infotech
Triggers
Trigger is an automatic event that happens based on
insert or update or delete
We cannot pass parameters to triggers
A trigger can happen before or after the operation
Create or replace trigger is used to get the trigger in
database
:NEW.column or :OLD.column is used to retrieve internal
values when the triggers are fired
Drop trigger is used to remove the trigger
To test a trigger, first do the required insert or delete or
update operation on the primary table
Do a select query on the other tables on which the
trigger operated
Softsmith Infotech
Stored Procedures
Exceptions
Exceptions must be handled inside stored
procedures or triggers
This will ensure that the code does not crash
When Others is the generic exception
SQLCODE and SQLERRM will hold the error
number and error text
Usually no_data_found and dup_val_on_index
are checked in most of the places
Softsmith Infotech
Cursors
When a stored procedure needs to retrieve only one
record, we use into clause in the select statement
When the procedure needs to process a record set, we
use cursor
Declare the cursor and provide the select statement
Use OPEN, FETCH and CLOSE commands to access
the cursor
Cursorname%notfound will be set to true if there are no
more records to fetch
Cursorname%count will provide the number of records in
the cursor
Softsmith Infotech
Sequences
Sequences are used to generate auto
increment values
Use Create sequence command and
provide minimum, maximum, start and
increment values
Sequcen.nextval will provide the next
sequence number
This can be used in any insert statements
subsequently
Softsmith Infotech
Constraints
Not Null is a constraint while creating a
table
Primary Key is a constraint
Foreign Key is a constraint
Check is a constraint to ensure that a
column has only specified values
Unique index is also a constraing
Softsmith Infotech
DBA Features
This list gives only the features and not detailed
information
Creating database
Creating users
Providing access rights to users across tables
Backup and restore
Crash recovery
Replication
Loading of bulk data
Partitioning of data across disks
Softsmith Infotech