Oracle Architecture Overview.

Slides:



Advertisements
Similar presentations
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Advertisements

Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
SQL’s Data Definition Language (DDL) n DDL statements define, modify and remove objects from data dictionary tables maintained by the DBMS n Whenever you.
Triggers The different types of integrity constraints discussed so far provide a declarative mechanism to associate “simple” conditions with a table such.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Harvard University Oracle Database Administration Session 2 System Level.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Database objects User schema DCL Oracle dictionary.
Using SQL Queries to Insert, Update, Delete, and View Data © Abdou Illia MIS Spring 2015 Wednesday 1/28/2015 Chapter 3A.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
Chapter 6 Additional Database Objects
Oracle Database Administration
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
In Oracle.  A PL/SQL block stored in the database and fired in response to a specified event ◦ DML statements : insert, update, delete ◦ DDL statements.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Chapter 3 Selected Single-Row Functions and Advanced DML & DDL.
1 ISYS Triggers. 2 Agenda Triggers Review Correlation identifiers (pseudo records) Restrictions on triggers Trigger usage Mutating tables Enabling.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CHAPTER 9 Views, Synonyms, and Sequences. Views are used extensively in reporting applications and also to present subsets of data to applications. Synonyms.
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
1 SQL - II Data Constraints –Applying data constraints Types of data constraints –I/O constraints The PRIMARY KEY constraints The FOREIGN KEY constraints.
Oracle 11g: SQL Chapter 4 Constraints.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Copyright  Oracle Corporation, All rights reserved. 11 Including Constraints.
Copyright  Oracle Corporation, All rights reserved. Introduction.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Schema Objects.
Objectives Database triggers and syntax
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
11 Including Constraints Objectives At the end of this lesson, you will be able to: Describe constraints Create and maintain constraints At the.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Visual Programing SQL Overview Section 1.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
Relational Database Management System(RDBMS) Structured Query Language(SQL)
PRACTICE OVERVIEW PL/SQL Part Your stored procedure, GET_BUDGET, has a logic problem and must be modified. The script that contains the procedure.
Dale Roberts 1 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
1 11g NEW FEATURES ByVIJAY. 2 AGENDA  RESULT CACHE  INVISIBLE INDEXES  READ ONLY TABLES  DDL WAIT OPTION  ADDING COLUMN TO A TABLE WITH DEFAULT VALUE.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
Oracle9i Developer: PL/SQL Programming Chapter 6 PL/SQL Packages.
1 Chapters 19 and 20  Ch. 19: By What Authority? Users Roles Grant and revoke Synonyms  Ch. 20: Changing the Oracle Surroundings Indexes Clusters Sequences.
Including Constraints
SQL Creating and Managing Tables
SQL Creating and Managing Tables
الأزنده أ.موضي المحرج.
SQL Creating and Managing Tables
Managing Objects with Data Dictionary Views
Managing Objects with Data Dictionary Views
SQL Statements SELECT INSERT UPDATE DELETE CREATE ALTER DROP RENAME
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Index Note: A bolded number or letter refers to an entire lesson or appendix. A Adding Data Through a View ADD_MONTHS Function 03-22, 03-23,
Contents Preface I Introduction Lesson Objectives I-2
Triggers.
Prof. Arfaoui. COM390 Chapter 7
Presentation transcript:

Oracle Architecture Overview

Oracle terms Schema – logical collection of user’s objects Tablespace – logical space used for storage Datafile – physical file used for storage Extent – group of contiguous blocks Block – unit of physical storage

System Global Area (SGA) Oracle Architecture database vs. instance Database Instance Parameter files* Control files** Data files Redo Log files System Global Area (SGA) Background Processes Memory Disk * Parameter files include the init<SID>.ora and config<SID>.ora files. These are used to set options for the database. ** Control files contain information about the db in binary form. They can be backed up to a text file however.

Oracle vs. Access and MySQL One .mdb file contains all objects Limited roles/permissions MySQL Three files per table Permissions based on user, database, and host Oracle Many files Many roles/permissions possible

The Oracle Data Dictionary Collection of tables and views that show the inner workings and structure of the db “static” data dictionary views owned by SYS created by catalog.sql script at db creation contain DDL info dynamic data dictionary views also referred to as V$ views based on virtual tables (X$ tables) provide info about the instance

More Data Dictionary 1. Samples table created in user’s schema Create table samples ( ID number(3) primary key, Type varchar2(5), Constraint type_ck check (type in (‘photo’,’swatch’)) …); 1. Samples table created in user’s schema 2. Primary key index created in user’s schema (SYS_C984620) 3. Data dictionary is also updated, with rows being inserted into tables underlying the following data dictionary views: User_objects User_constraints User_cons_columns And lots more…

Oracle Odds and Ends Dual table % - the SQL wildcard inserting apostrophes Case sensitive string matching SELECT 1+1*400 FROM DUAL; SELECT ename FROM emp WHERE ename like ‘%neil%’; INSERT INTO emp (name) VALUES (‘O’’Neill); UPDATE emp SET ename=UPPER(ename) WHERE ename='O''Neill';

Sysdate ADATE Sysdate returns current system date AND time use trunc function to remove time piece Example: select to_char (adate, ‘dd-mon-yy hh24:mi:ss’) TO_CHAR(ADATE, ‘DD-MON-YY:HH24:MI:SS’) 17-feb-00 23:41:50 select adate from samples where trunc(adate)=‘17-feb-00’; ADATE 17-FEB-00

ROWID ROWID is an internal number Oracle uses to uniquely identify each row NOT a primary key! Is the actual location of a row on a disk. Very efficient for retrieval. Format specifies block, row, and file (and object in 8) Oracle 7: BBBBBBB.RRRR.FFFFF Oracle 8: OOOOOO.FFF.BBBBBB.RRR Called pseudo-column since can be selected

Outer joins in Oracle Add (+) to table where nulls are acceptable SELECT * FROM emp, dept WHERE emp.deptno(+)=dept.id;

Oracle SQL functions Upper(), lower() Substr(), replace(), rtrim(), concat() Length() Floor(), sqrt(), min(), max(), stddev() Add_months(), months_between(), last_day() To_date(), to_char(), to_lob()

More functions nvl() decode() If NULL, return this instead… Nvl(lastname,’Anonymous’) decode() Sort of like an If/Then statement… Decode(gender,0,’Male’,1,’Female’,’Unknown’)

Oracle error messages Divided into groups by first three letters (e.g. ORA or TNS) Number gives more information about error Several messages may be related to only one problem oerr facility

Constraints Primary key Foreign key Unique, not null Check Name your constraints User_constraints, user_cons_columns CREATE TABLE test ( id NUMBER(2), col2 VARCHAR2(2), col3 VARCHAR2(3), CONSTRAINT test_pk PRIMARY KEY(id), CONSTRAINT col3_ck CHECK (col3 IN ('yes','no')) );

NAME T SEARCH_CONDITION --------------- - ------------------------- SELECT user_constraints.constraint_name name, constraint_type type, user_constraints.search_condition FROM user_constraints, user_cons_columns WHERE user_constraints.table_name=user_cons_columns.table_name AND user_constraints.constraint_name=user_cons_columns.constraint_name AND user_constraints.owner=user_cons_columns.owner AND user_constraints.table_name=‘TEST’; NAME T SEARCH_CONDITION --------------- - ------------------------- COL3_CK C col3 IN ('yes','no') TEST_PK P

Constraints Oracle naming of constraints is NOT intuitive! enabling and disabling disable constraint constraint_name; the EXCEPTIONS table run utlexcpt.sql to create EXCEPTIONS table then alter SQL statement: SQL_query EXCEPTIONS into EXCEPTIONS; What constraints do *YOU* have in your schema? @h:\..\chaffin\shared\scripts\utlexcpt.sql

More objects Sequences Synonyms creating the sequence create sequence CustomerID increment by 1 start with 1000; selecting from the sequence insert into customer (name, contact, ID) values (‘TManage’,’Kristin Chaffin’,CustomerID.NextVal); CurrVal is used after NextVal for related inserts Synonyms provide location and owner transparency Can be public or private

PL/SQL - Triggers Executed on insert, update, delete Use to enforce business logic that can’t be coded through referential integrity or constraints Types of triggers row level (use FOR EACH ROW clause) statement level (default) Before and After triggers Referencing old and new values

Trigger example SQL> desc all_triggers; Name Null? Type ------------------------------- -------- ---- OWNER VARCHAR2(30) TRIGGER_NAME VARCHAR2(30) TRIGGER_TYPE VARCHAR2(16) TRIGGERING_EVENT VARCHAR2(75) TABLE_OWNER VARCHAR2(30) BASE_OBJECT_TYPE VARCHAR2(16) TABLE_NAME VARCHAR2(30) COLUMN_NAME VARCHAR2(4000) REFERENCING_NAMES VARCHAR2(128) WHEN_CLAUSE VARCHAR2(4000) STATUS VARCHAR2(8) DESCRIPTION VARCHAR2(4000) ACTION_TYPE VARCHAR2(11) TRIGGER_BODY LONG

Trigger example (cont.) SQL> select trigger_name from all_triggers where owner='SCOTT'; TRIGGER_NAME ------------------------------ AFTER_INS_UPD_ON_EMP set lines 120 col trigger_name format a20 col triggering_event format a18 col table_name format a10 col description format a26 col trigger_body format a35 select trigger_name, trigger_type, triggering_event, table_name, status, description, trigger_body from all_triggers where trigger_name='AFTER_INS_UPD_ON_EMP';

Trigger example (cont.) SQL> / TRIGGER_NAME TRIGGER_TYPE TRIGGERING_EVENT TABLE_NAME STATUS DESCRIPTION -------------------- ---------------- ------------------ ---------- -------- ----------------------- TRIGGER_BODY ----------------------------------- AFTER_INS_UPD_ON_EMP BEFORE EACH ROW INSERT OR UPDATE EMP ENABLED scott.after_ins_upd_on_emp before insert or update on scott.emp for each row begin :new.ename := upper(:new.ename); end; The above trigger was created with the following statement: create or replace trigger scott.after_ins_upd_on_emp before insert or update on scott.emp for each row begin :new.ename := upper(:new.ename); end;

Remember those views? Query USER_TRIGGERS to get trigger info Query USER_SOURCE to get source of procedure, function, package, or package body Query USER_ERRORS to get error information (or use show errors) col name format a15 col text format a40 select name, type, text from user_errors order by name, type, sequence; Query USER_OBJECT to get status info

Understanding Indexes Index overhead impact on inserts, updates and deletes batch inserts can be slowed by indexes - may want to drop, then recreate rebuilding indexes Use indexes when query will return less than 5% of rows in a large table Determining what to index All primary and foreign keys Examine SQL and index heavily hit, selective columns (columns often found in where clauses)

What not to Index…preferably columns that are constantly updated columns that contain a lot of null values columns that have a poor distribution of data Examples: yes/no true/false male/female

B*-tree index Branch blocks Leaf blocks Miller Deal – ROWID < Davis Davis Jones Smith Turner Turner > Adams Brown Culver Deal Howard Isis Jules Klein Main Moss Porter Sikes Sykes Thomas Topper Vera Wagner Yanks 1+ levels of branch blocks – these contain info about range of values contained in next level. Only 1 level of leaf blocks – contain actual index values and rowids for associated rows “Depth” of index refers to the number of branch levels between the root and leaf blocks. Reverse key index reverses the values before storing them (e.g. value of ‘ABCD’ would be stored as ‘DCBA’) – this tends to address the problem of standard b*tree indexes where they become unbalanced over time (and thus less efficient and deeper, requiring more depth on the right side than the left side due to growth and deletion of values over time). Function-based indexes can be either b*tree or bitmap and are simply based on the results of a function, rather than on the value of a row. Leaf blocks Deal – ROWID Howard – ROWID Isis - ROWID Detail of leaf node Figure 4-1. in Oracle Essentials (2001). Greenwald, et.al. O’Reilly. p 92

Bitmap index Parts table Bitmapped index on ‘color’ partno color size 1 2 3 4 GREEN RED RED BLUE MED MED SMALL LARGE Bitmapped index on ‘color’ color = ‘BLUE’ color = ‘RED’ color = ‘GREEN’ 0 0 0 1 0 1 1 0 1 0 0 0 Part number 1 2 3 4 Figure 4-2. in Oracle Essentials (2001). Greenwald, et.al. O’Reilly. p 95