Chapter 14 Data Dictionary and Scripting

Similar documents
ORACLE VIEWS ORACLE VIEWS. Techgoeasy.com

Get Oracle Schema Ddl Syntax With Dbms_metadata

Appendix A Practices and Solutions

Oracle 8i User Guide for CS2312

Database Programming with SQL

Oracle MOOC: SQL Fundamentals

Misc. Triggers Views Roles Sequences - Synonyms. Eng. Mohammed Alokshiya. Islamic University of Gaza. Faculty of Engineering

Oracle ILM Assistant Installation Guide Version 1.4

SQL is an English like language consisting of commands to store, retrieve, maintain & regulate access to your database.

Lab # 1. Introduction to Oracle

Chapter 1 SQL and Data

Creating and Managing Tables Schedule: Timing Topic

Question: Which statement would you use to invoke a stored procedure in isql*plus?

Oracle Database 10g: Introduction to SQL

Database Administration and Management

Sqlplus To Create The Plan_table In Your Schema

Alter Change Default Schema Oracle Sql Developer

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Load data into Table from external files, using two methods:

Getting started with Oracle

Getting Started With Oracle

2. Software Oracle 12c is installed on departmental server machines.

Full file at

Using SQL Developer. Oracle University and Egabi Solutions use only

Oracle Database: Introduction to SQL

Introduction p. 1 The Logical and Physical View of Tables p. 1 Database Types p. 4 NULLs p. 6 DDL and DML Statements p. 7 Column and Table Constraint

UNIT 4 DATABASE SYSTEM CATALOGUE

Oracle Database: Introduction to SQL

Assignment 6. This lab should be performed under the Oracle Linux VM provided in the course.

Installing and Configuring Oracle 10g Express Edition. for use with the ETM System

Oracle Database: Introduction to SQL

Oracle User Administration

ORACLE TRAINING. ORACLE Training Course syllabus ORACLE SQL ORACLE PLSQL. Oracle SQL Training Syllabus

To create a private database link, you must have the CREATE

How To Drop All Tables In A Schema In Oracle 10g

PPDM Meta Model Practical Applications

1. Using Bitvise SSH Secure Shell to login to CS Systems Note that if you do not have Bitvise ssh secure shell on your PC, you can download it from

Create A Private Database Link In Another Schema In Oracle 11g Drop >>>CLICK HERE<<<

AO3 - Version: 2. Oracle Database 11g SQL

ORACLE DATABASE 12C INTRODUCTION

Oracle Database 11g: Introduction to SQLRelease 2

Set Current Schema Command Oracle Sql Developer Alter Session

Tablespace Usage By Schema In Oracle 11g Query To Check Temp

MySQL Introduction. By Prof. B.A.Khivsara

Structured Query Language. ALTERing and SELECTing

A <column constraint> is a constraint that applies to a single column.

Oracle Database: SQL Fundamentals II. Oracle Internal & Oracle Academy Use Only. Volume II Student Guide. D64260GC10 Edition 1.0 January 2010 D64500

CHAPTER. Oracle Database 11g Architecture Options

Data Definition Language (DDL)

Index. Boolean expression, , Business rules enforcement. see Declarative constraints table with Oracle constraints and,

CS6312 DATABASE MANAGEMENT SYSTEMS LABORATORY L T P C

Oracle Tables TECHGOEASY.COM

The Encryption Wizard for Oracle. API Library Reference

Vendor: Oracle. Exam Code: 1Z Exam Name: Oracle Database: SQL Fundamentals I. Q&As: 292

SQL+PL/SQL. Introduction to SQL

1Z0-071 Exam Questions Demo Oracle. Exam Questions 1Z Oracle Database 12c SQL.

Certification Exam Preparation Seminar: Oracle Database SQL

Lab # 2. Data Definition Language (DDL) Eng. Alaa O Shama

"Charting the Course... Oracle18c SQL (5 Day) Course Summary

When a database trigger routine does not have to take place before the triggering event, which timing should you assign to the trigger?

PL/SQL Developer 7.0 New Features. December 2005

Oracle Database 12c: SQL Fundamentals. Part COPYRIGHTED MATERIAL

Lecture 07. Spring 2018 Borough of Manhattan Community College

SYSTEM CODE COURSE NAME DESCRIPTION SEM

Tutorial 1 Database: Introductory Topics

MDCStore High Content Data Management Solution Database Schema

Oracle SQL. murach s. and PL/SQL TRAINING & REFERENCE. (Chapter 2)

Oracle Sql Describe Schemas Query To Find Database

Database Systems Laboratory 5 Grouping, DCL & TCL

SQL: DDL. John Ortiz Cs.utsa.edu

CHAPTER4 CONSTRAINTS

Oracle PLSQL Training Syllabus

5. Single-row function

Log File Management Tool Deployment and User's Guide. Initializing the DBMS

Oracle Sql Describe Schema Query To Find Table

Projects. Corporate Trainer s Profile. CMM (Capability Maturity Model) level Project Standard:- TECHNOLOGIES

1Z0-071 Exam Questions Demo Oracle. Exam Questions 1Z Oracle Database 12c SQL.

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

Oracle 11g Invisible Indexes Inderpal S. Johal. Inderpal S. Johal, Data Softech Inc.

SQL Fundamentals. Chapter 3. Class 03: SQL Fundamentals 1

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Lecture7: SQL Overview, Oracle Data Type, DDL and Constraints Part #2

MDCStore 2.0 DATABASE. Installation Guide

Oracle Database 12c SQL Fundamentals

SQLLIMS_RECORDS_API: Defines constants and record types used by the other API packages. This package is available as well for end-user use.

ORACLE Reference. 2. Modify your start-up script file using Option 1 or 2 below, depending on which shell you run.

Triggers- View-Sequence

Oracle Database 12c: Program with PL/SQL Duration: 5 Days Method: Instructor-Led

Table of Contents. Oracle SQL PL/SQL Training Courses

Oracle SQL. January 9, DaiMuHong

Lab # 4. Data Definition Language (DDL)

Oracle EXAM - 1Z Program with PL/SQL. Buy Full Product.

Prepared by Manash Deb website: 1

Course Outline and Objectives: Database Programming with SQL

Schema Validate With Oracle 10g Database Status

APEX Times Ten Berichte. Tuning DB-Browser Datenmodellierung Schema Copy & Compare Data Grids. Extension Exchange.

Manually configuring Oracle 12c IBM

Sanity-check the operating systems of all machines involved with user performance. By sanity-checking. Two of the biggest

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

COURSE CONTENT. ORACLE 10g/11g DBA. web: call: (+91) / 400,

Transcription:

Chapter 14 Data Dictionary and Scripting Tables in the Oracle Database User Tables Collection of tables to store data Data Dictionary Tables Collection of tables created and maintained by Oracle server Not directly accessible users typically access the data dictionary via views Owned by the user SYS 1 2 Data Dictionary Views Dynamic Views Begin with v$ Are continuously updated to monitor system performance Generally for DBA usage Example Static Views SELECT username FROM v$session; Information including users, privileges granted to users, database object names, table constraints, and auditing information 3 prefixes USER_ view information regarding user s own schema objects ALL_ view information on user s own objects and those GRANTed DBA_ view information regarding all objects (must be DBA) Querying the Data Dictionary USER_OBJECTS (pg 620) describes all objects owned by the current user tables, views, sequences, indexes, synonyms, functions, procedures, triggers, packages, others DESC USER_OBJECTS SELECT object_name, object_type, created, status FROM USER_OBJECTS ORDER BY object_type, object_name; Note: data dictionary views display object names in UPPER case 3 4 1

Who Has Created their Payment Table? ALL_OBJECTS describes objects owned by the current user and objects the current user has privileges to use DESC ALL_OBJECTS Confirming Views USER_VIEWS (pg 623, we used in Ch13) contains details of each view owned by the current user DESC USER_VIEWS SELECT owner, object_name, to_char(created, 'yyyy/mm/dd hh:mi') FROM ALL_OBJECTS WHERE object_name='payment' AND object_type='table' AND created > (SYSDATE - 120) ORDER BY 3; SELECT view_name, text FROM USER_VIEWS; 5 6 Confirming Tables USER_TABLES (pg 621) describes base tables owned by the current user DESC USER_TABLES Gathering Statistics (lib, pg 804+) The Oracle Optimizer uses object statistics to determine how to efficiently execute SQL statements Oracle does not continuously update object statistics Oracle 10g schedules GATHER_STATS_JOB collects statistics on database objects when the object has no previously gathered statistics or the existing statistics are stale because the underlying object has been modified significantly (eg: >10% of the rows) For how long are these statistics accurate? Can execute DBMS_STATS to gather statistics on the spot 7 8 2

Confirming Table Columns USER_TAB_COLUMNS (pg 622) describes the columns of current user s tables and views DESC USER_TAB_COLUMNS SELECT column_name, data_type, data_precision, data_scale, avg_col_len FROM USER_TAB_COLUMNS WHERE table_name = 'ARTICLE'; What Data Dictionary Views Are Available? DICTIONARY (pg 617) shows the name & a comment for each data dictionary view the current user can use DESC DICT 9 10 What Do The Columns in a Data Dictionary View Mean? DICT_COLUMNS (pg 626) shows the name & a comment for each column in a data dictionary view DESC DICT_COLUMNS Data Dictionary Practice Which data dictionary views seem to relate to constraints? 11 12 3

Confirming Constraints USER_CONSTRAINTS (pg 624+) describes the constraints on tables owned by the current user constraint type codes: C P R U V O Viewing the Columns Associated with Constraints USER_CONS_COLUMNS (pg 626) shows which column(s) a constraint operates on especially useful for constraints with a system-assigned name Practice Time what does USER_CONS_COLUMNS show for the ENROLLMENT table? 13 14 USER_CONSTRAINTS Joining Dictionary Views USER_CONS_COLUMNS Related views can be joined via a common column CONSTRAINT_NAME is common to USER_CONSTRAINTS and USER_CONS_COLUMNS show details for WRITER table s constraints and columns they act upon Practice Time What would a join of USER_CONSTRAINTS and USER_CONS_COLUMNS show for the ENROLLMENT table? Both UCC UC UC 15 16 4

Object Dependencies Some objects are dependent on other objects eg: a view depends on and USER_DEPENDENCIES (pg 624) describes dependencies between views, procedures, packages, functions, and triggers owned by the current user DESC USER_DEPENDENCIES Retrieving an Object s DDL (nib?) The Data Dictionary contains each object s definition Can use DBMS_METADATA.GET_DDL to extract the SQL statement that defines the object SELECT DBMS_METADATA.GET_DDL('TABLE', 'RECEIPT', 'TTROLLEN') FROM DUAL; SELECT DBMS_METADATA.GET_DDL('SEQUENCE','EVENS_SEQ') FROM DUAL; SELECT DBMS_METADATA.GET_DDL('VIEW','ARTICLE_WRITER') FROM DUAL; 17 18 Scripting and Reporting Lab 14.2 Common SQL*Plus Commands (pg 860+) Changes to database objects will be developed and tested in a development testbed, then applied to the production schema What is a script? a text file containing SQL statements and SQL*Plus commands ensures the same series of DML/DDL statements executed in production as testbed 2 Ways to run a script from SQL Developer open the script file and run it or [F5] start command The default script filename extension is.sql What is the default script location? Preferences > Database > Worksheet Parameters > Select default path to look for scripts 19 DESCRIBE comments single-line -- or REM multi-line /* */ SPOOL filename SET ECHO {ON OFF} controls whether or not the Script Output pane shows commands when a script executes SET DEFINE {& c ON OFF} controls whether or not SQL Developer scans commands for substitution variables and replaces them with their values. ON changes the value of c back to the default &, not the most recently used c SET VERIFY {ON OFF} controls whether the the Script Output pane shows substitution variable details SET FEEDBACK {6 n ON OFF} displays the row count when a statement returns at least n rows eg: '9 rows selected' SET FEEDBACK OFF suppresses the row count and also suppresses statement confirmation messages eg: 'Table created' ACCEPT UNDEFINE PAUSE PROMPT sets the character used to prefix substitution variables to c 20 5

SQL*Plus Substitution Variables What is a variable? In SQL*Plus and SQL Developer, & indicates that what follows is a substitution variable Substitution variables make SQL statements more versatile When a substitution variable is embedded in a SQL statement, SQL Developer substitutes the variable s value into the statement, prompting for its value if not previously created, before sending the statement to Oracle Can be created explicitly ACCEPT DEFINE Will be created implicitly if not previously created 21 Practice Time: Substitution Variables Open a new worksheet, then enter these statements Save this script as constraints.sql Run the script Note: how substitution variables were resolved row count is displayed 22 Demo: Substitution Variables ACCEPT (pg 650+) ACCEPT variable [NUMBER CHAR DATE] [FORMAT format] [PROMPT text] [HIDE] A SQL*Plus command regrettably, seems to have limited functionality in SQL Developer Defines a variable, its data type, and a prompt message ACCEPT v_table CHAR PROMPT 'Which table?' ACCEPT hired DATE FORMAT 'mm/dd/yyyy' - DEFAULT '01/01/2010' PROMPT 'Enter hire date:' ACCEPT v_length NUMBER PROMPT 'What size?' ACCEPT pw CHAR PROMPT 'Password' HIDE The variable retains its value until exit SQL*Developer or the variable is explicitly UNDEFINEd can refer to the variable throughout the session without getting prompted for each occurrence 23 24 6

UNDEFINE A SQL*Plus command Deletes variables that were defined either explicitly (ACCEPT, DEFINE) or implicitly Generating Dynamic SQL What does all this concatenation produce? UNDEFINE v_table UNDEFINE pw DEFINE 25 Thus we can use SQL to generate SQL 26 Generate Dynamic SQL Place the generated rows to a text file to build a script -- disable_enrollment.sql Prompt This script disables the constraints for table ENROLLMENT ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_MODIFIED_DATE_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_STUDENT_ID_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_ENROLL_DATE_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_MODIFIED_BY_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_SECTION_ID_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_CREATED_BY_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_CREATED_DATE_NNULL; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_PK; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_STU_FK; ALTER TABLE ENROLLMENT DISABLE CONSTRAINT ENR_SECT_FK; 27 7