Oracle Academy Egypt Virtual training week 8 Sections from 7 to 9.

Slides:



Advertisements
Similar presentations
Oracle 10g & 11g for Dev Virtual Columns DML error logging
Advertisements

Structured Query Language (SQL)
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Using DDL Statements to Create and Manage Tables
11 Copyright © Oracle Corporation, All rights reserved. Managing Tables.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
SQL2-ch2 管理綱要物件.
Data Definition Language (DDL)
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
SQL - Subqueries and Schema Chapter 3.4 V3.0 Napier University Dr Gordon Russell.
Manipulating Data Schedule: Timing Topic 60 minutes Lecture
17 Copyright © 2005, Oracle. All rights reserved. Performing Flashback.
Virtual training week 4 structured query language (SQL)
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Copyright © 2011 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are trademarks of Accenture. SQL Workshop Day 4.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Introduction to Structured Query Language (SQL)
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Other database objects (Sequence). What Is a Sequence? A sequence: Automatically generates sequential numbers Is a sharable object Is typically used to.
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.
SQL (DDL & DML Commands)
DATA MANIPULATION andCONTROL
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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.
20 Copyright © Oracle Corporation, All rights reserved. Oracle9 i Extensions to DML and DDL Statements.
Objectives After completing this lesson, you should be able to do the following: Describe each data manipulation language (DML) statement Insert rows.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
4 Copyright © 2007, Oracle. All rights reserved. Manipulating Large Data Sets.
Database Programming Sections 7 & 8 – Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE, DELETE, integrity constraint,
3 Copyright © 2006, Oracle. All rights reserved. Manipulating Large Data Sets.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Managing Constraints. 2 home back first prev next last What Will I Learn? Four different functions that the ALTER statement can perform on constraints.
Visual Programing SQL Overview Section 1.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
2 Copyright © 2006, Oracle. All rights reserved. Managing Schema Objects.
Database Programming Sections 7–Multi-row sub queries, IN, ANY, ALL, Data Manipulation Language (DML) transaction, INSERT, implicit, explicit, USER, UPDATE,
Chapter 12 Additional Database Objects. Chapter Objectives  Define the purpose of a sequence and state how it can be used by an organization  Explain.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
© 2006 Northgate Information Solutions plc and its associated companies. All rights reserved. Slide 1.
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
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)
1 DBS201: More on SQL Lecture 2. 2 Agenda Select command review How to create a table How to insert data into a table.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
 CONACT UC:  Magnific training   
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
What is the Flashback Database? Improves a database’s availability Useful alternative to traditional restoration methods Contains Flashback logs Archived.
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
Insert, update, delete TCL. Data Manipulation Language – A DML statement is executed when you: Add new rows to a table Modify existing rows in a table.
Chapter 5 Introduction to SQL.
SQL: Schema Definition and Constraints Chapter 6 week 6
ATS Application Programming: Java Programming
Using the Set Operators
Manipulating Data.
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
DBS201: More on SQL Lecture 2.
IST 318 Database Administration
Presentation transcript:

Oracle Academy Egypt Virtual training week 8 Sections from 7 to 9

Oracle Academy Egypt Create table copy_departments As (select * from departments) This syntax used to create table with same structure and same data type and all rows of the originL Table with other name. _____________________________________________ Create table sales_reps As (select * from employees Where 1 = 2) This syntax used to create table with same structure and same data type but without any row.

Oracle Academy Egypt

Multi-table inserts can be unconditional or conditional. In an unconditional multitable insert Oracle will insert all rows returned by the subquery into all table insert clauses found in the statement. In a conditional multi-table insert you can specify either ALL or FIRST. ALL If you specify ALL, the default value, then the database evaluates each WHEN clause regardless of the results of the evaluation of any other WHEN clause. For each WHEN clause whose condition evaluates to true, the database executes the corresponding INTO clause list. FIRST If you specify FIRST, then the database evaluates each WHEN clause in the order in which it appears in the statement. For the first WHEN clause that evaluates to true, the database executes the corresponding INTO clause and skips subsequent WHEN clauses for the given row. ELSE clause For a given row, if no WHEN clause evaluates to true, then: If you have specified an ELSE clause, then the database executes the INTO clause list associated with the ELSE clause. If you did not specify an else clause, then the database takes no action for that row.

Oracle Academy Egypt INSERT ALL INTO all_calls VALUES (caller_id, call_timestamp, call_duration, call_format) INTO police_record_calls VALUES (caller_id, call_timestamp, recipient_caller) SELECT caller_id, call_timestamp, call_duration, call_format, recipient_caller) FROM calls WHERE TRUNC(call_timestamp ) = TRUNC(SYSDATE ) Multitable insert Unconditional

Oracle Academy Egypt Multi-Table Inserts Conditional INSERT ALL WHEN call_ format IN (tlk,txt,pic) THEN INTO all_calls VALUES (caller_id, call_timestamp, call_duration, call_format) WHEN call_ format IN (tlk,txt) THEN INTO police_record_calls VALUES (caller_id, call_timestamp, recipient_caller) WHEN call_duration < 50 AND call_type = tlkTHEN INTO short_calls VALUES (caller_id, call_timestamp, call_duration) WHEN call_duration > = 50 AND call_type = tlkTHEN INTO long_calls VALUES (caller_id, call_timestamp, call_duration) SELECT caller_id, call_timestamp, call_duration, call_format, recipient_caller) FROM calls WHERE TRUNC(call_timestamp ) = TRUNC(SYSDATE )

Oracle Academy Egypt

We can use single row subquery only to update rows

Oracle Academy Egypt Department table didn't have department_id 55

Oracle Academy Egypt Note/ If no where condition is used all rows in the table will be deleted

Oracle Academy Egypt

Data copied from items table to copy_items table

Oracle Academy Egypt

0 If you dont enter any value a 0 will be entered, same time any other number (value) can be entered The length of the character is up to 10 characters

Oracle Academy Egypt In this case 0 will be added

Oracle Academy Egypt External Tables an external table would be used to store data migrated from older versions of the databases used by a company. The syntax to create an external table Same syntax for creating table in addition to the following ….. ORGANIZATION EXTERNAL -- tells Oracle to create an external table (TYPE ORACLE_LOADER -- of type Oracle Loader (an Oracle Product) DEFAULT DIRECTORY def_dir1 -- what is the name of the directory where the file exists ACCESS PARAMETERS -- how to read the file (RECORDS DELIMITED BY NEWLINE -- how to identify a new row starts FIELDS – the start of the external file field name and datatype specification... LOCATION – name of the actual file containing the data

Oracle Academy Egypt CREATE TABLE emp_load (employee_number CHAR(5), employee_dob CHAR(20), employee_last_name CHAR(20), employee_first_name CHAR(15), employee_middle_name CHAR(15), employee_hire_date DATE) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY def_dir1 ACCESS PARAMETERS (RECORDS DELIMITED BY NEWLINE FIELDS (employee_number CHAR(2), employee_dob CHAR(20), employee_last_name CHAR(18), employee_first_name CHAR(11), employee_middle_name CHAR(11), employee_hire_date CHAR(10) date_format DATE mask "mm/dd/yyyy)) LOCATION ('info.dat'));

Oracle Academy Egypt Data dictionary contains what is called meta data (data of data)

Oracle Academy Egypt Show all available views in your schema Show the names of all tables in your schema Show all objects available in your schema Show the names of the objects and their titles in your schema

Oracle Academy Egypt

Sometimes tables dont be dropped if therere dependences (PK and FK between two tables)

Oracle Academy Egypt

Flashback This command can be used to restore a table, a view or an index that was dropped in error. Also used to view row data at specific points in time, so we can compare different versions of a row over time. (We can use this facility to look at what the rows looked like BEFORE those changes were applied)

Oracle Academy Egypt FLASHBACK TABLE FLASHBACK TABLE tablename TO BEFORE DROP; Note/ As the owner of a table you can issue the flashback command, and if the table that you are restoring had any indexes, then these are also restored.

Oracle Academy Egypt FLASHBACK QUERY A typical flashback query might look like this: SELECT versions_starttime AS "START_DATE", versions_endtime AS "END_DATE", salary FROM employees VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE WHERE department_id = 90;

Oracle Academy Egypt

FLASHBACK QUERY SELECT versions_starttime "START_DATE", versions_endtime "END_DATE", salary FROM employees VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE WHERE department_id=90 Rows from the oldupdated version are in red in the output table below:

Oracle Academy Egypt NOTE Oracle is getting the FLASHBACK QUERY data from the before images held in the database in the UNDO tablespace. Typically, this UNDO data is only available for up to 15 minutes after the transaction was committed. Once the UNDO data has been overwritten by Oracle, Flashback queries are no longer possible, so if you want to use this functionality, you will have to do it quickly after the changes were committed.

Oracle Academy Egypt

clients_client_num_pk SYS_C When the constraint is created, it can be given a name, such as clients_client_num_pk, or given no name, in which case the system gives the constraint a name, such as SYS_C Note: If the word CONSTRAINT is used in the CREATE TABLE definition, you must give the constraint a name. It is best to name constraints yourself. Why? The system-generated names are not intuitive. You can do better than the database when it comes to naming!

Oracle Academy Egypt

clients_ _nn_not null

GOOD LUCK SEE YOU NEXT MEETING Raafat Rashad