0% found this document useful (0 votes)
64 views

Course Code: Comp 324 Course Name: Database Management System II Lecture 1: Introduction To DBMS II

This document provides an overview of Database Management System II. It discusses database applications, how they access databases through dynamic SQL, embedded SQL, and APIs. Embedded SQL allows SQL statements to be included in programming code by declaring host variables. Cursors bridge the gap between SQL's set-based queries and languages without sets by retrieving rows one at a time.

Uploaded by

Mutuba Neema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Course Code: Comp 324 Course Name: Database Management System II Lecture 1: Introduction To DBMS II

This document provides an overview of Database Management System II. It discusses database applications, how they access databases through dynamic SQL, embedded SQL, and APIs. Embedded SQL allows SQL statements to be included in programming code by declaring host variables. Cursors bridge the gap between SQL's set-based queries and languages without sets by retrieving rows one at a time.

Uploaded by

Mutuba Neema
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Course Code: Comp 324

Course Name: Database Management System II

Lecture 1: Introduction to DBMS II

Lecturer Name: Laura Limo


Devotional Meditation

Psalm 23:1
The LORD is my shepherd, I shall not be in want.
Lecture Outline
1. Course Outline Overview
2. Introduction
3. Database applications
4. Functions of database applications
5. Access to Databases
6. Embedded SQL
7. Cursors
8. Class Activity (Moodle)
Recap from DBMS I
Recap from DBMS I
Database Applications
• Database applications are separate programs that invoke or are
connected to the DBMS e.g grading system, timetabling system,
examination system etc.
• These applications can be online/web-based applications or
stand-alone applications.
• Applications that rely on the DBMS to manage data run on as
separate processes that connect to the DBMS to interact with it.
• Once a connection has been established, SQL commands can
be used to insert, delete and modify data and SQL queries can
be used to retrieve data from database.
Functions of Database Applications
• To process views of data i.e. to create, read, update and delete
(CRUD)- Four basic processing functions.
• To format or materialize the views that are being processed.
Formats such as reports, forms etc
• Enforcing constraints e.g. requiring data values to fit domain
specifications, ensuring uniqueness, and enforcing relationship
constraints
• To provide mechanisms for security and control
• To execute business logic.
Applications Accessing Databases
Applications can access databases via:
• Dynamic SQL – This is where a query is allowed to be constructed and executed at
runtime.
• Embedded SQL
• Cursors
• API (Application Programming Interface) – for instance ODBC (Open Database
Connectivity) and JDBC (Java Database Connectivity) enable the integration of SQL with
general purpose programming language

NB: There is a difference between how database system views data and how applications
view data i.e. the results of a database query is a set (multiset) of records, but for instance,
Java has no set or multiset data type.
How SQL can be used
SQL can be used in two ways:
• As an interactive query language and database
programming language.
• Including both DDL and DML statements, SQL can be
embedded in an application program.

How would these ways benefit the programmers/application


developers?
Embedded SQL
• Embedded SQL allows us to • Host variables are special variables
access data using static SQL defined for the purpose of providing a
queries in application code. mechanism to pass values between the
programs languages used to develop the
• By embedding SQL statements in a
application and the SQL statements that
c/c++/java program, one can write communicate with the database server.
application programs in c/c++/java • The data types of the host variables must
that interact (CRUD) with the be compatible with the data types of the
database. columns in the database tables.
• SQL statements must be clearly • The host variables must be declared
marked so that the pre-processor between the commands EXEC SQL
BEGIN DECLARE SECTION and EXEC
can deal with them before invoking
SQL END DECLARE SECTION
the compiler for the host language.
Problems of Embedded SQL
Two problems may arise in embedding SQL in application programs:
• The data types recognized by SQL may not be recognized by the
host language and vice versa. This is addressed by casting data
values appropriately before passing them to or from SQL
commands.
• Impedance mismatch: Where SQL queries return sets of records
(multiset), of which the host does not support. This difference is
resolved using additional SQL constructs –cursors, that allow
applications to obtain a handle on the collection and iterate over the
records one at a time.
Cursors
• Cursor is a mechanism used in • It is then opened- this positions the
embedded SQL that allows the cursor just before the first row.
host program to access the rows • Fetch statement is then used
of a query one at a time i.e. They several times to retrieve the rows of
bridge the gap between set-valued the query one at a time i.e. Fetch
query answers and programming the next row.
languages that do not support set • Move is also used with the Fetch
values. command to move the cursor to a
• Thus, the cursor is declared on particular row e.g move to the
any relation or SQL SELECT previous row.
query. • Once all the results have been
retrieved the cursor is then closed.
Conclusion

Database Applications

How applications access databases

Embedded SQL

Cursors

You might also like