Escolar Documentos
Profissional Documentos
Cultura Documentos
Training
3
What is a database?
SMP
Informix
Server
IN
INDatabase
Database
SMAP SMAP SMAP
SCP
DBClient (User)
DBClient (DBA)
5
Tables
A database in a RDBMS
is a collection of
information that is
grouped into one or more
tables.
Stock
6
Tables are relational
100 1100.00 0
101 2200.00 1
7
Rows
Rows
Each row of a table
stands for one
instance of the
subject of the table,
which is one
particular example
of that entity.
Stock
8
Columns
Columns
Each column of a
table stands for one
attribute, which is
one characteristic,
feature, or fact that
is true of the subject
of the table.
Stock
9
Operations on Tables
10
Database Objects
Object Description
Table Basic unit of storage; composed of rows
and columns
11
What is a View?
EMPLOYEES Table:
12
Why Use Views?
13
What are Constraints?
An index:
Is a schema object
Is used by the Oracle server to speed up the
retrieval of rows by using a pointer
Can reduce disk I/O by using a rapid path access
method to locate data quickly
Is independent of the table it indexes
Is used and maintained automatically by the Oracle
server
15
How Are Indexes Created?
16
Data Types
Data Type Description
VARCHAR2(size) Variable-length character data
CHAR(size) Fixed-length character data
NUMBER(p,s) Variable-length numeric data
DATE Date and time values
LONG Variable-length character data
up to 2 gigabytes
CLOB Character data up to 4
gigabytes
RAW and LONG RAW Raw binary data
BLOB Binary data up to 4 gigabytes
BFILE Binary data stored in an external
file; up to 4 gigabytes
ROWID A 64 base number system representing
the unique address of a row in its table.
17
Summary
18
SQL Statement
Objectives
20
SQL Statements
INSERT
UPDATE Data manipulation language (DML)
DELETE
CREATE
ALTER Data definition language (DDL)
DROP
TRUNCATE
COMMIT
ROLLBACK
SAVEPOINT Data control language (DCL)
GRANT
REVOKE
21
Limiting the Rows Selected
22
Using Arithmetic Operators
23
Column Aliases
24
Literal Character Strings
25
Duplicate Rows
26
Using the WHERE Clause
27
Character Strings and Dates
28
Comparison Conditions
Operator Meaning
= Equal to
29
Other Comparison Conditions
Operator Meaning
30
Using the BETWEEN Condition
31
Using the IN Condition
32
Using the LIKE Condition
33
Using the NULL Conditions
34
Logical Conditions
Operator Meaning
35
Using the AND Operator
36
Using the NOT Operator
37
ORDER BY Clause
Sort rows with the ORDER BY clause
ASC: ascending order, default
DESC: descending order
The ORDER BY clause comes last in the SELECT statement.
38
Data Manipulation Language
39
The INSERT Statement Syntax
40
Inserting New Rows
42
Copying Rows
from Another Table
4 rows created.
43
The UPDATE Statement Syntax
44
Updating Rows in a Table
45
Updating Rows Based
on Another Table
UPDATE copy_emp
SET department_id = (SELECT department_id
FROM employees
WHERE employee_id = 100)
WHERE job_id = (SELECT job_id
FROM employees
WHERE employee_id = 200);
1 row updated.
46
The DELETE Statement
DELETE
DELETE [FROM]
[FROM] table
table
[WHERE
[WHERE condition];
condition];
47
Deleting Rows from a Table
DELETE
DELETE FROM
FROM departments
departments
WHERE
WHERE department_name
department_name == 'Finance';
'Finance';
11 row
row deleted.
deleted.
48
Deleting Rows Based
on Another Table
49
Database Transactions
50
Database Transactions
51
Controlling Transactions
Time
COMMIT
Transaction
DELETE
SAVEPOINT A
INSERT
UPDATE
SAVEPOINT B
52
Rolling Back Changes
to a Marker
53
Implicit Transaction Processing
54
Committing Data
INSERT
INSERT INTO
INTO departments
departments
VALUES
VALUES (290,
(290, 'Corporate
'Corporate Tax',
Tax', NULL,
NULL, 1700);
1700);
11 row
row inserted.
inserted.
COMMIT;
Commit the changes.
Commit complete.
55
State of the Data After ROLLBACK
56
Writing SQL Statements
57
Summary
58
Practice
59
Functions
Objectives
61
SQL Functions
Input Output
Function
arg 1 Function
performs action
arg 2
Result
value
arg n
62
Character Functions
Character
functions
Case-manipulation Character-manipulation
functions functions
LOWER CONCAT
UPPER SUBSTR
INITCAP LENGTH
INSTR
LPAD | RPAD
TRIM
REPLACE
63
Case Manipulation Functions
Function Result
LOWER('SQL Course') sql course
UPPER('SQL Course') SQL COURSE
INITCAP('SQL Course') Sql Course
64
Using Case Manipulation Functions
65
Character-Manipulation Functions
Function Result
CONCAT('Hello', 'World') HelloWorld
SUBSTR('HelloWorld',1,5) Hello
LENGTH('HelloWorld') 10
INSTR('HelloWorld', 'W') 6
LPAD(salary,10,'*') *****24000
RPAD(salary, 10, '*') 24000*****
TRIM('H' FROM 'HelloWorld') elloWorld
66
Using the Character-Manipulation Functions
1 2 3
67
Number Functions
68
Date Functions
Function Description
69
Using Date Functions
MONTHS_BETWEEN ('01-SEP-95','11-JAN-94')
19.6774194
NEXT_DAY ('01-SEP-95','FRIDAY')
'08-SEP-95'
LAST_DAY('01-FEB-95') '28-FEB-95'
70
Conversion Functions
Data type
conversion
71
Using the TO_CHAR Function with Dates
TO_CHAR(date,
TO_CHAR(date, 'format_model')
'format_model')
72
Elements of the Date Format Model
73
Using the TO_CHAR Function with Dates
SELECT last_name,
TO_CHAR(hire_date, 'fmDD Month YYYY')
AS HIREDATE
FROM employees;
74
Using the TO_NUMBER and TO_DATE
Functions
Convert a character string to a number format
using the TO_NUMBER function:
TO_NUMBER(char[,
TO_NUMBER(char[, 'format_model'])
'format_model'])
Convert a character string to a date format using
the TO_DATE function:
TO_DATE(char[,
TO_DATE(char[, 'format_model'])
'format_model'])
76
Practice
77
Questions and Answers
78