Download presentation
Presentation is loading. Please wait.
Published byLily King Modified over 9 years ago
1
Programming and SQL Edel Sherratt
2
Motivation 1: Integrity Checking Sometimes primary keys and foreign keys are not enough For example, they do not enforce mandatory participation on the many side of a one-to- many relationship So additional facilities are needed
3
Integrity Checking (from before) Primary Keys Foreign Keys Referential Integrity Unique/NOT NULL Simple Efficient Preferred (Available in all DBMS) SQL stored modules: Stored Procedures Triggers Functions Whenever necessary and possible Application CodeIf all else fails
4
Motivation 2: Impedance mismatch Mismatches between application programming language and SQL SQL handles rows of data; a language like C or Java handles only one row at a time SQL is declarative; C is procedural; Java is object oriented and imperative There are usually mismatches between SQL and programming language data types
5
SQL/PSM (Persistent Stored Modules) Extensions to SQL part of the SQL standard: SQL/PSM (ANSI/ISO/IEC 9075-4:1999) But not fully implemented Partly because proprietary implementations were developed before the standard
6
SQL Programming Languages DBMS-specific SQL procedural languages: – Oracle: PL/SQL – Sybase and Microsoft: T-SQL – Informix: SPL – PostgreSQL: PL/pgSQL
7
Oracle Manual, v10 Using Oracle PL/SQL to improve performance
8
SQL Programming Language Constructs Functions and procedures IF, WHILE Assignment: both the usual kind and also assignment that results from SQL queries Cursors: allow the rows of a query to be handled one at a time Exception handling Triggers
9
To find out more The PostgreSQL reference manual: http://www.postgresql.org/docs/9.1/static/in dex.html See section V, Server Programming http://www.postgresql.org/docs/9.1/static/in dex.html Oracle PL/SQL: http://www.oracle.com/technetwork/databas e/features/plsql/index.html http://www.oracle.com/technetwork/databas e/features/plsql/index.html Connolly and Begg, Database Systems, fifth ed., Chapter 8: Advanced SQL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.