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

lecture 2

This document discusses the architecture of database systems, including centralized, client-server, and distributed models, and outlines the roles of storage managers and query processors. It also covers transaction management, relational databases, and the different types of data models, such as relational, entity-relationship, object-based, and semi-structured models. Additionally, it explains the use of SQL for data manipulation and definition, as well as the interaction between application programs and databases through APIs like ODBC and JDBC.

Uploaded by

zainab.haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

lecture 2

This document discusses the architecture of database systems, including centralized, client-server, and distributed models, and outlines the roles of storage managers and query processors. It also covers transaction management, relational databases, and the different types of data models, such as relational, entity-relationship, object-based, and semi-structured models. Additionally, it explains the use of SQL for data manipulation and definition, as well as the interaction between application programs and databases through APIs like ODBC and JDBC.

Uploaded by

zainab.haider
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lecture 2

Databases and Transactions

Second stage

Department of Cyber Security Engineering

Alshaab University
Preparation:Assist.Lect: Zainab mohammed
Zainab haider
Database Architecture:
The architecture of a database system is greatly influenced by the underlying
computer system on which the database system runs. Database systems can
be centralized, or client-server, where one server machine executes work on
behalf of multiple client machines. Database systems can also be designed to
exploit parallel computer architectures. Distributed databases span multiple
geographically separated machines.
A database system is partitioned into modules that deal with each of the
responsibilities of the overall system. The functional components of a
database system can be broadly divided into the storage manager and the
query processor components. The storage manager is important because
databases typically require a large amount of storage space. The query
processor is important because it helps the database system simplify and
facilitate access to data.

It is the job of the database system to translate updates and queries written in
a non procedural language, at the logical level, into an efficient sequence of
operations at the physical level.
Database applications are usually partitioned into two or three parts, as in
Figure 1.4. In two-tier architecture, the application resides at the client
machine, where it invokes database system functionality at the server
machine through query language statements. Application program interface
standards like ODBC and JDBC are used for interaction between the client
and the server. In contrast, in a three-tier architecture, the client machine acts
as merely a front end and does not contain any direct database calls. Instead,

1
the client end communicates with an application server, usually through a
forms interface.
The application server in turn communicates with a database system to
access data. The business logic of the application, which says what actions
to carry out under what conditions, is embedded in the application server,
instead of being distributed across multiple clients. Three-tier applications
are more appropriate for large applications, and for applications that run on
the Worldwide Web.

Transaction Manager:
A transaction is a collection of operations that performs a single logical
function in a database application. Each transaction is a unit of both
atomicity and consistency. Thus, we require that transactions do not violate

2
any database-consistency constraints. That is, if the database was consistent
when a transaction started, the database must be consistent when the
transaction successfully terminates. Transaction - manager ensures that the
database remains in a consistent (correct) state despite system failures (e.g.,
power failures and operating system crashes) and transaction failures.

Relational Databases
A relational database is based on the relational model and uses a collection
of tables to represent both data and the relationships among those data. It
also includes a DML and DDL
1-Tables
Each table has multiple columns and each column has a unique name. Figure
1.2 presents a sample relational database comprising two tables: one shows
details of university instructors and the other shows details of the various
university departments. The first table, the instructor table, shows, for
example, that an instructor named Einstein with ID 22222 is a member of
the Physics department and has an annual salary of $95,000. The second
table, department, shows, for example, that the Biology department is
located in the Watson building and has a budget of $90,000. Of course, a
real-world university would have many more departments and instructors.
We use small tables in the text to illustrate concepts. A larger example for
the same schema is available online. The relational model is an example of a
record-based model. Record-based models are so named because the
database is structured in fixed-format records of several types. Each table
contains records of a particular type. Each record type defines a fixed
number of fields, or attributes. The columns of the table correspond to the
attributes of the record type. It is not hard to see how tables may be stored in
3
files. For instance, a special character (such as a comma) may be used to
delimit the different attributes of a record, and another special character
(such as a new-line character) may be used to delimit records. The relational
model hides such low-level implementation details from database developers
and users. We also note that it is possible to create schemas in the relational
model that have problems such as unnecessarily duplicated information. For
example, suppose we store the department budget as an attribute of the
instructor record. Then, whenever the value of a particular budget (say that
one for the Physics department) changes, that change must to be reflected in
the records of all instructors

4
2- Data-Manipulation Language
The SQL query language is non procedural. A query takes as input several
tables (possibly only one) and always returns a single table. Here is an
example of an SQL query that finds the names of all instructors in the
History department:

The query specifies that those rows from the table instructor where the dept
name is History must be retrieved, and the name attribute of these rows must
be displayed. More specifically, the result of executing this query is a table
with a single column
labeled name, and a set of rows, each of which contains the name of an
instructor whose dept name, is History. If the query is run on the table in
Figure 1.2, the result will consist of two rows, one with the name El Said
and the other with the name Califieri. Queries may involve information from
more than one table. For instance, the following query finds the instructor ID
and department name of all instructors associated with a department with
budget of greater than $95,000.
select instructor.ID, department.dept name
from instructor, department
where instructor.dept name= department.dept name and
department.budget > 95000;

If the above query were run on the tables in Figure 1.2, the system would
find that there are two departments with budget of greater than $95,000—

5
Computer Science and Finance; there are five instructors in these
departments. Thus, the result will consist of a table with two columns (ID,
dept name) and five rows: (12121, Finance), (45565, Computer Science),
(10101, Computer Science), (83821, Computer Science), and (76543,
Finance)
3- Data-Definition Language
SQL provides a rich DDL that allows one to define tables, integrity
constraints, assertions, etc. For instance, the following SQL DDL statement
defines the department table:
create table department
(dept name char (20),
building char (15),
budget numeric (12,2));
Execution of the above DDL statement creates the department table with
three columns: dept name, building, and budget, each of which has a specific
data type associated with it. We discuss data types in more detail in Chapter
3. In addition, the DDL statement updates the data dictionary, which
contains metadata (see Section 1.4.2). The schema of a table is an example
of metadata.
4- Database Access from Application Programs
SQL is not as powerful as a universal Turing machine; that is, there are some
computations that are possible using a general-purpose programming
language but are not possible using SQL. SQL also does not support actions
such as input from users, output to displays, or communication over the
network. Such computations and actions must be written in a host language,
such as C, C++, or Java, with embedded SQL queries that access the data in

6
the database. Application programs are programs that are used to interact
with the database in this fashion.
Examples in a university system are programs that allow students to register
for courses, generate class rosters, calculate student GPA, generate payroll
checks, etc. To access the database, DML statements need to be executed
from the host language. There are two ways to do this:
 By providing an application program interface (set of procedures)
that can be used to send DML and DDL statements to the database
and retrieve the results
The Open Database Connectivity (ODBC) standard for use with the C
language is a commonly used application program interface standard. The
Java Database Connectivity (JDBC) standard provides corresponding
features to the Java language
 By extending the host language syntax to embed DML calls within the
host language program. Usually, a special character prefaces DML
calls, and a preprocessor, called the DML precompiler, converts the
DML statements to normal procedure calls in the host language.
Data Models
Underlying the structure of a database is the data model: a collection of
conceptual tools for describing data, data relationships, data semantics, and
consistency constraints. A data model provides a way to describe the design
of a database at the physical, logical, and view levels.
The data models can be classified into four different categories:

A) Relational Model. The relational model uses a collection of tables to


represent both data and the relationships among those data. Each table has
multiple columns, and each column has a unique name. Tables are also

7
known as relations. The relational model is an example of a record-based
model.
Record-based models are so named because the database is structured in
fixed-format records of several types. Each table contains records of a
particular type. Each record type defines a fixed number of fields, or
attributes. The columns of the table correspond to the attributes of the
record type. The relational data model is the most widely used data model,
and a vast majority of current database systems are based on the relational
model.

B) Entity-Relationship Model. The entity-relationship (E-R) data model


uses a collection of basic objects, called entities, and relationships among
these objects.
An entity is a “thing” or “object” in the real world that is distinguishable
from other objects. The entity- relationship model is widely used in
database design.

C) Object-Based Data Model. Object-oriented programming (especially in


Java, C++, or C#) has become the dominant software-development
methodology. This led to the development of an object-oriented data model
that can be seen as extending the E-R model with notions of encapsulation,
methods (functions), and object identity. The object-relational data model
combines features of the object-oriented data model and relational data
model.

D) Semi-structured Data Model. The semi-structured data model permits


the specification of data where individual data items of the same type may

8
have different sets of attributes. This is in contrast to the data models
mentioned earlier, where every data item of a particular type must have the
same set of attributes. The Extensible Markup Language (XML) is widely
used to represent semi-structured data
Historically, the network data model and the hierarchical data model
preceded the relational data model. These models were tied closely to the
underlying implementation, and complicated the task of modeling data. As a
result they are used little now, except in old database code that is still in
service in some places.

You might also like