database foundation training

14
Database Foundation Training Feb. 2011

Upload: franky-lao

Post on 05-Jul-2015

390 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Database Foundation Training

Database Foundation TrainingFeb. 2011

Page 2: Database Foundation Training

Database & DBMS

Insert, Update, Delete, Select

Create. Drop, Alter, Truncate

Page 3: Database Foundation Training

Categories of Database

Categories

Relational Database (RDBMS)

Microsoft SQL Server

Oracle

Sybase

IBM

Mysql

Flat File Database

Lotus Notes

Page 4: Database Foundation Training

Objects of Database

Objects

Database

Schema

Table

View

Synonym

Store Procedure

Function

Trigger

Page 5: Database Foundation Training

Table

Table

Column Name

Data Type

Data Length

Nullable

Default Value

Constraint (PK. FK)

Index

Page 6: Database Foundation Training

Index

Index

B-Tree Index

Bitmap Index

Hash Index

Reverse Index

...

ID Name Corporation Country

…. …. ….. ….

1258 Kong IBM CN

1259 Kong IBM CN

…. … … …

1335 ZhaoPing HP EN

Select * From Tab1Where Name=‘Kong’ And Corporation=‘IBM’ And Country=‘CN’

Page 7: Database Foundation Training

View

View

Views can represent a subset of the data contained in a table

Views can join and simplify multiple tables into a single virtual table

Views can act as aggregated tables, where the database engine aggregates data (sum, average etc) and presents the calculated results as part of the data

Views can hide the complexity of data; for example a view could appear as Sales2000 or Sales2001, transparently partitioning the actual underlying table

Views take very little space to store; the database contains only the definition of a view, not a copy of all the data it presents

Depending on the SQL engine used, views can provide extra security

Views can limit the degree of exposure of a table or tables to the outer world

Page 8: Database Foundation Training

Store Procedure & Function

Store Procedure

CREATE { PROC | PROCEDURE } [schema_name.] procedure_name [ ;number ] [ { @parameter [ type_schema_name. ] data_type } [ VARYING ] [ = default ] [ OUT | OUTPUT ] [READONLY] ] [ ,...n ] [ WITH <procedure_option> [ ,...n ] ] [ FOR REPLICATION ] AS { [ BEGIN ] sql_statement [;] [ ...n ] [ END ] } [;]

Function

CREATE FUNCTION [ schema_name. ] function_name( [ { @parameter_name [ AS ][ type_schema_name. ] parameter_data_type [ = default ] [ READONLY ] } [ ,...n ] ] ) RETURNS return_data_type [ WITH <function_option> [ ,...n ] ] [ AS ] BEGIN function_body RETURN scalar_expression END [ ; ]

Page 9: Database Foundation Training

Trigger

Trigger

{CREATE | RECREATE | CREATE OR ALTER} TRIGGER name

FOR {TABLE name | VIEW name}

[ACTIVE | INACTIVE]

{BEFORE | AFTER} {INSERT [OR UPDATE] [OR DELETE] | UPDATE [OR INSERT] [OR DELETE] | DELETE [OR UPDATE] [OR INSERT] }

[POSITION n]

AS BEGIN ..... END

Page 10: Database Foundation Training

Synonym

Synonym

Public Synonym

CREATE PUBLIC SYNONYM employees for hr.employees;

Private Synonym

CREATE SYNONYM addresses FOR hr.locations;

Page 11: Database Foundation Training

Transaction

Transaction

1. To provide reliable units of work that allow correct recovery from failures and keep a database consistent even in cases of system failure, when execution stops (completely or partially) and many operations upon a database remain uncompleted, with unclear status.

2. To provide isolation between programs accessing a database concurrently. Without isolation the program's outcomes are possibly erroneous.

Page 12: Database Foundation Training

How DML works

Oracle Client

3.1 Syntax Validation

3.2 Objects Validation

3.3 Objects Locks

3.4 Access Right of Objects Validation

3.5 Explain Plan

Sql Query Cache

Sql Query Cache

2/5

. SQ

L query +

Plan

2. SQL query

1. SQL query

Database

4. SQL query + Plan

6. SQL query + Plan

4.Exception

Page 13: Database Foundation Training

Database vs. Data Warehouse

OLTP (Online Transaction Processing)

OLAP (Online Analysis Processing)

Page 14: Database Foundation Training

Q & A

Questions?