1 Categories of SQL Statements Data definition statements Data manipulation statements Cursor manipulation statements Cursor optimization statements Dynamic.

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

Virtual training week 4 structured query language (SQL)
Module 15: Managing Transactions and Locks. Overview Introduction to Transactions and Locks Managing Transactions SQL Server Locking Managing Locks.
System Administration Accounts privileges, users and roles
Harvard University Oracle Database Administration Session 2 System Level.
Security and Transaction Management Pertemuan 8 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Fundamentals, Design, and Implementation, 9/e Chapter 7 Using SQL in Applications.
LOCKS Locks are mechanisms used to ensure data integrity while allowing maximum concurrent access to data. Oracle's locking is fully automatic and requires.
Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Agenda Journalling More Embedded SQL. Journalling.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
9 Copyright © 2005, Oracle. All rights reserved. Administering User Security.
Database Programming Sections 13–Creating, revoking objects privileges.
SQL Server 7.0 Maintaining Referential Integrity.
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
7 Copyright © 2004, Oracle. All rights reserved. Administering Users.
Controlling User Access. Objectives After completing this lesson, you should be able to do the following: Create users Create roles to ease setup and.
Triggers and Stored Procedures in DB 1. Objectives Learn what triggers and stored procedures are Learn the benefits of using them Learn how DB2 implements.
Stored Procedures Week 9. Test Details Stored Procedures SQL can call code written in iSeries High Level Languages –Called stored procedures SQL has.
Introduction to Oracle. Oracle History 1979 Oracle Release client/server relational database 1989 Oracle Oracle 8 (object relational) 1999.
KKUI Manažérske informačné Systémy Cvičenia 2010 Zdenek Marhefka.
Commercial RDBMSs Access and Oracle. Access DBMS Architchecture  Can be used as a standalone system on a single PC: -JET Engine -Microsoft Data Engine.
© 2011 IBM Corporation 15 June 2011 Triggers and Stored Procedure Language (SPL)
Controlling User Access Fresher Learning Program January, 2012.
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
1 Announcements Reading for next week: Chapter 4 Your first homework will be assigned as soon as your database accounts have been set up.  Expect an .
Transactions, Roles & Privileges Oracle and ANSI Standard SQL Lecture 11.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
IST 318 Database Administration Lecture 9 Database Security.
Database Security. Multi-user database systems like Oracle include security to control how the database is accessed and used for example security Mechanisms:
Module 11: Managing Transactions and Locks
Relational Database Management System(RDBMS) Structured Query Language(SQL)
1 Database Fundamentals Introduction to SQL. 2 SQL Overview Structured Query Language The standard for relational database management systems (RDBMS)
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
MY SQL INTRODUCTION TO LOGIN BASIC COMMANDS OTHER COMMANDS.
SQL Basics Review Reviewing what we’ve learned so far…….
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Implicit Commit Statements That Cause an Implicit Commit The statements listed in this section (and any synonyms for them) implicitly end any transaction.
Controlling User Access
Controlling User Access
Managing Privileges.
Controlling User Access
Controlling User Access
Managing Privileges.
The Basics of Data Manipulation
IS221: Database Management
Active Database Concepts
Database Security.
Introduction To Database Systems
Introduction to Triggers
LAB: Web-scale Data Management on a Cloud
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Database Security.
Module 5: Implementing Data Integrity by Using Constraints
Overview Implementing Triggers Implementing XML Schemas.
Data base System Concepts & Data Modeling
Chapter 5 Sequences.
The Basics of Data Manipulation
SQL Fundamentals in Three Hours
SQL .. An overview lecture3.
Chapter 7 Using SQL in Applications
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Managing Privileges.
Chapter 7 Using SQL in Applications
Information Management
Presentation transcript:

1 Categories of SQL Statements Data definition statements Data manipulation statements Cursor manipulation statements Cursor optimization statements Dynamic management statements Data access statements Data integrity statements Optimization statements Routine Definition statements Auxiliary statements Client/server connection statements Optical subsystem statements

2 Data Definition Statements ALTER FRAGMENTALTER FUNCTION ALTER INDEXALTER PROCEDURE ALTER ROUTINEALTER TABLE CLOSE DATABASECREATE AGGREGATE CREATE CASTCREATE DATABASE CREATE DISTINCT TYPECREATE EXTERNAL TABLE CREATE INDEXCREATE OPAQUE TYPE CREATE PROCEDURECREATE PROCEDURE FROM CREATE ROLECREATE ROW TYPE CREATE SCHEMACREATE SYNONYM CREATE TABLECREATE TEMPORARY TABLE CREATE TRIGGERCREATE VIEW DATABASEDROP AGGREGATE DROP CASTDROP DATABASE DROP INDEXDROP PROCEDURE DROP ROLEDROP ROW TYPE DROP SYNONYMDROP TABLE DROP TRIGGERDROP VIEW RENAME COLUMNRENAME DATABASE RENAME TABLETRUNCATE

3 Data Manipulation Statements DELETEINSERT LOADSELECT UNLOADUPDATE Cursor Manipulation Statements CLOSEDECLARE FETCHFLUSH FREEOPEN PUTSET AUTOFREE Optimization Statements SET AUTOFREE SET DEFERRED_PREPARE

4 Dynamic Management Statements ALLOCATE COLLECTIONALLOCATE DESCRIPTOR ALLOCATE ROWDEALLOCATE COLLECTION DEALLOCATE DESCRIPTORDEALLOCATE ROW DESCRIBEEXECUTE EXECUTE IMMEDIATEFREE GET DESCRIPTORPREPARE SET DEFERRED_PREPARESET DESCRIPTOR Data Access Statements GRANTGRANT FRAGMENT LOCK TABLEREVOKE REVOKE FRAGMENTSET ISOLATION SET LOCK MODESET ROLE SET SESSION AUTHORIZATIONSET TRANSACTION SET TRANSACTION MODEUNLOCK TABLE

5 Data Integrity Statements BEGIN WORKCOMMIT WORK ROLLBACK WORKSET DATABASE OBJECT MODE SET LOGSET PLOAD FILE SET TRANSACTION MODESTART VIOLATIONS TABLE STOP VIOLATIONS TABLE Optimization Statements SET EXPLAINSET OPTIMIZATION SET PDQPRIORITYSET RESIDENCY SET SCHEDULE LEVELSET STATEMENT CACHE UPDATE STATISTICS

6 Routine Definition Statements ALTER FUNCTIONALTER PROCEDURE ALTER ROUTINECREATE FUNCTION CREATE FUNCTION FROMCREATE PROCEDURE CREATE PROCEDURE FROMCREATE ROUTINE FROM DROP FUNCTIONDROP PROCEDURE DROP ROUTINEEXECUTE FUNCTION EXECUTE PROCEDURESET DEBUG FILE TO

7 Auxiliary Statements INFOOUTPUT GET DIAGNOSTICSSET DATASKIP WHENEVER Client/Server Connection Statements CONNECTDISCONNECT SET CONNECTION Optical Subsystem Statements ALTER OPTICAL CLUSTERCREATE OPTICAL CLUSTER DROP OPTICAL CLUSTERRELEASE RESERVESET MOUNTING TIMEOUT

8 Data Type

9

10 CREATE DATABASE

11 CREATE SCHEMA

12 CREATE TABLE

13 CREATE TABLE 1

14 CREATE TABLE 2

15 CREATE TABLE 3

16 CREATE TABLE 4

17 CREATE TABLE 5

18 CREATE INDEX

19 TRIGGER A mechanism that resides in the database. It is available to any user who has permission to use it. Specifies that when a particular action, an insert, a select, a delete, or an update, occurs on a particular table, the database server should automatically perform one or more additional actions. The additional actions can be INSERT, DELETE, UPDATE, EXECUTE PROCEDURE or EXECUTE FUNCTION statements.

20 CREATE TRIGGER 1

21 CREATE TRIGGER 2

22 CREATE TRIGGER 3

23 CREATE TRIGGER 4

24 CREATE TRIGGER 5

25 CREATE PROCEDURE 1

26 CREATE PROCEDURE 2

27 CREATE PROCEDURE 3

28 Example 1: CREATE TRIGGER upqty UPDATE OF quantity ON items BEFORE (EXECUTE PROCEDURE upd_items_p1) Example 2: CREATE PROCEDURE upd_items_p1() DEFINE GLOBAL old_qty INT DEFAULT 0; LET old_qty = (SELECT SUM(quantity) FROM items); END PROCEDURE; CREATE PROCEDURE upd_items_p2() DEFINE GLOBAL old_qty INT DEFAULT 0; DEFINE new_qty INT; LET new_qty = (SELECT SUM(quantity) FROM items; IF new_qty > old_qty * 1.50 THEN RAISE EXCEPTION –746, 0, ‘Not allowed / rule violation;’ END IF END PROCEDURE;

29 Example 3: CREATE TRIGGER up_items UPDATE OF quantity ON items BEFORE(EXECUTE PROCEDURE upd_items_p1()) AFTER(EXECUTE PROCEDURE upd_items_p2());

30 Example 4: FOR EACH ROW clause, REFERENCING clause CREATE TABLE log_record (item_numSMALLINT, ord_numINTEGER, usernameCHAR(8), update_timeDATETIME YEAR TO MINUTE, old_qtySMALLINT, new_qtySMALLINT); CREATE TRIGGER upqty UPDATE OF quantity ON items REFERENCING OLD AS pre_upd NEW AS post_upd FOR EACH ROW (INSERT INTO log_record VALUES (pre_upd.item_num, pre_upd.order_num, USER, CURRENT year to fraction(3), pre_upd.quantity, post_upd.quantity));

31 Example 5: WHEN condition CREATE TRIGGER up_price UPDATE OF unit_price ON stock REFERENCING OLD AS pre NEW AS post FOR EACH ROW WHEN (post.unit_price > pre.unit_price * 2) (INSERT INTO warn_tab VALUES (pre.stock_num, pre.order_num, pre.unit_price, post.unit_price, CURRENT))

32 Example 6: passing data to SPL procedure CREATE TRIGGER upd_totpr UPDATE OF quantity ON items REFERENCING OLD AS pre_upd NEW AS post_upd FOR EACH ROW(EXECUTE PROCEDURE calc_totpr(pre_upd.quantity, post_upd.quantity, pre_upd.total_price) INTO total_price) CREATE PROCEDURE calc_totpr(old_qty SMALLINT, new_qty SMALLINT, total MONEY(8)) RETURNING MONEY(8); DEFINE u_price LIKE items.total_price; DEFINE n_total LIKE items.total_price; LET u_price = total / old_qty; LET n_total = new_qty * u_price; RETURN n_total; END PROCEDURE

33 Zdroje: Informix Dynamic Server 2000, Product Documentation