Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Advanced SQL.

Similar presentations


Presentation on theme: "© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Advanced SQL."— Presentation transcript:

1 © 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Advanced SQL

2 Chapter 8 © 2007 by Prentice Hall 2 Conditional Expressions Using Case Syntax This is available with newer versions of SQL, previously not part of the standard

3 Chapter 8 © 2007 by Prentice Hall 3 Ensuring Transaction Integrity Transaction = A discrete unit of work that must be completely processed or not processed at all Transaction = A discrete unit of work that must be completely processed or not processed at all May involve multiple updates May involve multiple updates If any update fails, then all other updates must be cancelled If any update fails, then all other updates must be cancelled SQL commands for transactions SQL commands for transactions BEGIN TRANSACTION/END TRANSACTION BEGIN TRANSACTION/END TRANSACTION Marks boundaries of a transaction Marks boundaries of a transaction COMMIT COMMIT Makes all updates permanent Makes all updates permanent ROLLBACK ROLLBACK Cancels updates since the last COMMIT Cancels updates since the last COMMIT

4 Chapter 8 © 2007 by Prentice Hall 4 Figure 8-5 An SQL Transaction sequence (in pseudocode)

5 Chapter 8 © 2007 by Prentice Hall 5 Data Dictionary Facilities System tables that store metadata System tables that store metadata Users usually can view some of these tables Users usually can view some of these tables Users are restricted from updating them Users are restricted from updating them Some examples in Oracle 10g Some examples in Oracle 10g DBA_TABLES–descriptions of tables DBA_TABLES–descriptions of tables DBA_CONSTRAINTS–description of constraints DBA_CONSTRAINTS–description of constraints DBA_USERS–information about the users of the system DBA_USERS–information about the users of the system Examples in Microsoft SQL Server 2000 Examples in Microsoft SQL Server 2000 SYSCOLUMNS–table and column definitions SYSCOLUMNS–table and column definitions SYSDEPENDS–object dependencies based on foreign keys SYSDEPENDS–object dependencies based on foreign keys SYSPERMISSIONS–access permissions granted to users SYSPERMISSIONS–access permissions granted to users

6 Chapter 8 © 2007 by Prentice Hall 6 SQL:1999 and SQL:2003 Enhancements/Extensions User-defined data types (UDT) User-defined data types (UDT) Subclasses of standard types or an object type Subclasses of standard types or an object type Analytical functions (for OLAP) Analytical functions (for OLAP) CEILING, FLOOR, SQRT, RANK, DENSE_RANK CEILING, FLOOR, SQRT, RANK, DENSE_RANK WINDOW–improved numerical analysis capabilities WINDOW–improved numerical analysis capabilities New Data Types New Data Types BIGINT, MULTISET (collection), XML BIGINT, MULTISET (collection), XML CREATE TABLE LIKE–create a new table similar to an existing one CREATE TABLE LIKE–create a new table similar to an existing one MERGE MERGE

7 Chapter 8 © 2007 by Prentice Hall 7 Persistent Stored Modules (SQL/PSM) Persistent Stored Modules (SQL/PSM) Capability to create and drop code modules Capability to create and drop code modules New statements: New statements: CASE, IF, LOOP, FOR, WHILE, etc. CASE, IF, LOOP, FOR, WHILE, etc. Makes SQL into a procedural language Makes SQL into a procedural language Oracle has propriety version called PL/SQL, and Microsoft SQL Server has Transact/SQL Oracle has propriety version called PL/SQL, and Microsoft SQL Server has Transact/SQL SQL:1999 and SQL:2003 Enhancements/Extensions (cont.)

8 Chapter 8 © 2007 by Prentice Hall 8 Routines and Triggers Routines Routines Program modules that execute on demand Program modules that execute on demand Functions–routines that return values and take input parameters Functions–routines that return values and take input parameters Procedures–routines that do not return values and can take input or output parameters Procedures–routines that do not return values and can take input or output parameters Triggers Triggers Routines that execute in response to a database event (INSERT, UPDATE, or DELETE) Routines that execute in response to a database event (INSERT, UPDATE, or DELETE)

9 Chapter 8 © 2007 by Prentice Hall 9 Figure 8-6 Triggers contrasted with stored procedures Procedures are called explicitly Triggers are event-driven Source: adapted from Mullins, 1995.

10 Chapter 8 © 2007 by Prentice Hall 10 Figure 8-7 Simplified trigger syntax, SQL:2003 Figure 8-8 Create routine syntax, SQL:2003

11 Chapter 8 © 2007 by Prentice Hall 11 Embedded and Dynamic SQL Embedded SQL Embedded SQL Including hard-coded SQL statements in a program written in another language such as C or Java Including hard-coded SQL statements in a program written in another language such as C or Java Dynamic SQL Dynamic SQL Ability for an application program to generate SQL code on the fly, as the application is running Ability for an application program to generate SQL code on the fly, as the application is running


Download ppt "© 2007 by Prentice Hall (Hoffer, Prescott & McFadden) 1 Advanced SQL."

Similar presentations


Ads by Google