Chapter1-Overview of Database Concepts
Chapter1-Overview of Database Concepts
Chapter1-Overview of Database Concepts
Compiled by Biruk M. 1
Users:
Characteristics:
o Traditionally data was organized in file formats. DBMS was all new concepts then and all
the research was done to make it to overcome all the deficiencies in traditional style of
data management. Modern DBMS has the following characteristics:
Real-world entity:.
Relation-based tables:
Isolation of data and application:.
Less redundancy:
Consistency:
Query Language:.
ACID Properties
Multiuser and Concurrent Access:.
Multiple views
Security:
Query language
o Having a central repository for all data and data descriptions allows the DML to
provide a general inquiry facility to this data,called a query language
DDL
Compiled by Biruk M. 2
o DDL is Data Definition Language and is used to define the structures like schema,
database, tables, constraints etc. Examples of DDL are create and alter statements.
(create,drop,rename,alter)
DML
o DML is Data Manipulation Language and is used to manipulate data. Examples of
DML are insert, update and delete statements.
Data Model:
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.
Relational Model.
o 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 known as relations. The relational
model is an example of a record-based model.
Entity-Relationship Model.
o 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 entityrelationship
model is widely used in database design.
Object-Based Data Model.
o 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.
o The object-relational data model combines features of the object-oriented data
model and relational data model.
o History: 1980 to 1990 – New data models like ODBMS, ORDBMS powerful
query languages, etc.
Semi-structured Data Model.
o The semi-structured data model permits the specification of data where individual
data items of the same type may 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.
(NoSQl/MongoDb-store unstructured,semistructured & structured data)
Old Data Models (network & hierarchical)
o preceded the relational data model. These models were tied closely to the
underlying implementation, and complicated the task of modeling data.
Compiled by Biruk M. 3
Database trends are changing?
Difficulties with RDBMS storage and usage
Demand for data in forms other than just text
Adoption of e-Business causes rise in online DBMS capacity demand.
Growth in e-commerce and enterprise portals….Creates market for open source
DBMS.
Demand for access through mobile devices….Mobile database suites
Current trends:
o Multimedia Databases (Media data)
o Distributed Database: (distribution and logical correlation)
o Document-oriented Databases:
Each record (document) might have a different format (number and
size of fields)
Don’t store data in tables with uniform sized fields for each record.
Instead, each record is stored as a document that has certain
characteristics.
Any number of fields of any length can be added to a document.
Fields can also contain multiple pieces of data.
o Mobile & embedded Databases
The new database applications include handling:
Spatial data (such as maps):spatial related information: Eg: a 2D satellite image may
be represented as raster each pixel registers the rain fall in a given area.
Geographic database applications
Forestry and ecology planning
Location of telephone and electric cables, pipes and sewage system
Vehicle navigation and dispatching system
Urban planning
Engineering design data (such as the design of buildings, system components or
integrated circuits)
Hypertext and multimedia (including text,images ,videos,and audio data)
Time related data (such as historical records stock exchange data)
World wide web ( a huge ,widely distributed information repository made available
by the internet
Firebase: Firebase is a Backend-as-a-Service (BaaS) app development platform that
provides hosted backend services such as a realtime database, cloud storage,
Compiled by Biruk M. 4
authentication, crash reporting, machine learning, remote configuration, and hosting
for your static files.
A distributed database
o is a collection of multiple, logically interrelated databases of the same
system distributed over various sites of a computer network.
o Sometimes "distributed database system" is used to refer jointly to the
distributed database and the distributed DBMS.
o Example:
All major social and professional networking sites use distributed
databases
Cloud computing services
o
Future: petabyte age (10 the power of 15 massive data)
Example of such queries:
How many female WWF fans under the age of 30 visited the Toyota
community over the last 4 days and saw a Class A advs? How are these
people similar to those that visited Nissan?
1.2 Object Oriented Databases
Object-oriented databases are a type of database management system. Different
database management systems provide additional functionalities. Object-oriented
databases add the database functionality to object programming languages, creating more
manageable code bases.
Compiled by Biruk M. 5
An object database is managed by an object-oriented database management system
(OODBMS). The database combines object-oriented programming concepts with
relational database principles.
o Objects are the basic building block and an instance of a class, where the type is
either built-in or user-defined.
o Classes provide a schema or blueprint for objects, defining the behavior.
o Methods determine the behavior of a class.
o Pointers help access elements of an object database and establish relations
between objects.
These characteristics make object databases suitable for projects with complex data
which require an object-oriented approach to programming. An object-oriented
management system provides supported functionality catered to object-oriented
programming where complex objects are central. This approach unifies attributes and
behaviors of data into one entity.
Object-oriented databases closely relate to object-oriented programming concepts. The
four main ideas of object-oriented programming are:
o Polymorphism:
is the capability of an object to take multiple forms. This ability allows the
same program code to work with different data types. Both a car and a
bike are able to break, but the mechanism is different. In this example, the
Compiled by Biruk M. 6
action break is a polymorphism. The defined action is polymorphic — the
result changes depending on which vehicle performs.
o Inheritance:
Inheritance creates a hierarchical relationship between related classes
while making parts of code reusable. Defining new types inherits all the
existing class fields and methods plus further extends them. The existing
class is the parent class, while the child class extends the parent.
For example, a parent class called Vehicle will have child
classes Car and Bike. Both child classes inherit information from the
parent class and extend the parent class with new information depending
on the vehicle type.
o Encapsulation
is the ability to group data and mechanisms into a single object to provide
access protection. Through this process, pieces of information and details
of how an object works are hidden, resulting in data and function security.
Classes interact with each other through methods without the need to
know how particular methods work.
As an example, a car has descriptive characteristics and actions. You can
change the color of a car, yet the model or make are examples of
properties that cannot change. A class encapsulates all the car information
into one entity, where some elements are modifiable while some are not.
o Abstraction
is the procedure of representing only the essential data features for the
needed functionality. The process selects vital information while
unnecessary information stays hidden. Abstraction helps reduce the
complexity of modeled data and allows reusability.
For example, there are different ways for a computer to connect to the
network. A web browser needs an internet connection. However, the
connection type is irrelevant. An established connection to the internet
represents an abstraction, whereas the various types of connections
represent different implementations of the abstraction.
Every database modeling technique has advantages and disadvantages. Before opting in for
object-oriented databases, you must know the available languages in addition to the application
intent.
Compiled by Biruk M. 7
Advantages
Complex data and a wider variety of data types compared to MySQL data types.
Easy to save and retrieve data quickly.
Seamless integration with object-oriented programming languages.
Easier to model the advanced real world problems.
Extensible with custom data types.
Disadvantages
Additional Readings:
Object-Oriented Database Examples:
There are different kinds of implementations of object databases. Most contain the following
features:
Feature Description
Query Language Language to find objects and retrieve data from the database.
Transparent
Ability to use an object-oriented programming language for data manipulation.
Persistence
ACID Transactions ACID transactions guarantee all transactions are complete without conflicting changes.
Creates a partial replica of the database. Allows access to a database from program mem
Database Caching
instead of a disk.
1. GemStone/S
GemStone/S is an object database system based on Smalltalk – an object-oriented
programming language influenced by Java. Developers who write applications in
Smalltalk adapt easily to this database. GemStone/S integrates seamlessly with
existing Smalltalk applications, improving speed and productivity.
2. ObjectDB
ObjectDB is a NoSQL object database for the Java programming language.
Compared to other NoSQL databases, ObjectDB is ACID compliant. ObjectDB does
not provide an API and requires using one of the two built-in Java database APIs:
Compiled by Biruk M. 8
o JPA with JPA Query Language (JPQL) based on Java syntax.
o JDO with JDO Query Language (JDQL) based on SQL syntax.
ObjectDB includes all basic data types in Java, user-defined classes, and standard
Java collections. Every object has a unique ID. The number of elements is limited
only by the maximum database size (128 TB). ObjectDB is available cross-platform
and the benchmark performance is exceptional.
3. ObjectDatabase++
ObjectDatabase++ is a real-time embeddable object database designed for
server-side applications. The required external maintenance is minimal.
ObjectDatabase++ supports:
o Multi-process with multi-threaded server applications.
o Full transaction control.
o Real-time recovery.
o C++ related languages, VB.NET as well as C#.
The object database is C++ based. One of the main features is advanced auto-
recovery from system crashes without compromising the database integrity.
4. Objectivity/DB
Objectivity/DB utilizes the power of objects and satisfies the complex requirements
within Big Data. The object database is flexible by supporting multiple languages:
o C++
o C#
o Python
o Java
The schema changes happen dynamically without the need for downtime, allowing
real-time queries against any data type. Objectivity/DB is available for multiple
platforms, including macOS, Linux, Windows, or Unix.
5. ObjectStore
ObjectStore integrates with C++ or Java and provides memory persistency to
improve the performance of application logic. The object database is ACID-
compliant. The responsiveness allows developers to build distributed applications
cross-platform, whether on-premises or in the cloud. The main feature is cloud
scalability, which allows database access from anywhere. ObjectStore simplifies the
data creation and exchange process seamlessly.
6. Versant
Versant provides primary transparent object persistence from C++, Java, and .NET. However,
there is also support for Smalltalk and Python. Versant supports different APIs depending on the
language used. Standard SQL queries are also available, making Versant a NoSQL database.The
object database is a multi-user client-server database. Versant performs best when used for
online transaction systems with large amounts of data and concurrency.
1.3 Object relational database systems
O-O-database:
based on the object oriented programming paradigm, where in general terms, each
entity is concerned as an object.
Compiled by Biruk M. 9
data and code relating to an object are encapsulated into a single unit
Object-oriented data model is seen as extending of E-R model with the notions of
encapsulation, method and object identity.
O-relational database:
Are constructed based on an object –relational data model
This model extends the relational model by providing a rich data type for handling
complex objects and object orientation.
In addition special constructs for relational query languages are included to manage the
added data types.
Are becoming increasingly popular in industry and applications.
Relational Database vs Object oriented Database (purchase_order application)
Entity relationship diagram of Purchase-Order Application
Compiled by Biruk M. 10
Examples of Relational database
Creating four tables for the entities in the system:
A. Customer_reltab
CREATE TABLE Customer_reltab (
CustNo bigint NOT NULL,
CustName VARCHAR(200) NOT NULL,
Street VARCHAR(200) NOT NULL,
City VARCHAR(200) NOT NULL,
State VARCHAR(200) NOT NULL,
Zip VARCHAR(20) NOT NULL,
Phone1 VARCHAR(20),
Phone2 VARCHAR(20),
Phone3 VARCHAR(20),
PRIMARY KEY (CustNo)
)
B. Stock_reltab
CREATE TABLE Stock_reltab (
StockNo bigint PRIMARY KEY,
Price decimal,
TaxRate decimal
)
C. PurchaseOrder_reltab
CREATE TABLE PurchaseOrder_reltab (
PONo bigint, /* purchase order no */
Custno bigint forein key references
Customer_reltab(Custno), /* Foreign KEY referencing
customer */
OrderDate DATE, /* date of order */
ShipDate DATE, /* date to be shipped */
ToStreet VARCHAR(200), /* shipto address */
ToCity VARCHAR(200),
ToState VARCHAR(200),
ToZip VARCHAR(20),
PRIMARY KEY(PONo)
) ;
D. LineItems_reltab
CREATE TABLE LineItems_reltab (
LineItemNo bigint,
PONo bigint forein key references
PurchaseOrder_reltab(PONo),
StockNo bigint forein key references
Stock_reltab(StockNo),
Quantity int,
Discount decimal
PRIMARY KEY (PONo, LineItemNo)
) ;
Compiled by Biruk M. 11
Inserting values in the four tables of the system:
Stock:
o INSERT INTO Stock_reltab VALUES(1004, 6750.00, 2) ;
o INSERT INTO Stock_reltab VALUES(1011, 4500.23, 2) ;
o INSERT INTO Stock_reltab VALUES(1534, 2234.00, 2) ;
o INSERT INTO Stock_reltab VALUES(1535, 3456.23, 2) ;
Customer:
o INSERT INTO Customer_reltab
VALUES (1, 'Jean Nance', '2 Avocet Drive',
'Redwood Shores', 'CA', '95054',
'415-555-1212', NULL, NULL) ;
LineItems:
o INSERT INTO LineItems_reltab VALUES(01, 1001, 1534, 12, 0) ;
o INSERT INTO LineItems_reltab VALUES(02, 1001, 1535, 10, 10) ;
o INSERT INTO LineItems_reltab VALUES(01, 2001, 1004, 1, 0) ;
o INSERT INTO LineItems_reltab VALUES(02, 2001, 1011, 2, 1) ;
Queries:
Get Customer and Line Item Data for a Specific Purchase Order
SELECT C.CustNo, C.CustName, C.Street, C.City, C.State,
C.Zip, C.phone1, C.phone2, C.phone3,
P.PONo, P.OrderDate,
L.StockNo, L.LineItemNo, L.Quantity, L.Discount
FROM Customer_reltab C,
PurchaseOrder_reltab P,
LineItems_reltab L
WHERE C.CustNo = P.CustNo
AND P.PONo = L.PONo
AND P.PONo = 1001 ;
Compiled by Biruk M. 12
WHERE P.PONo = L.PONo
AND L.StockNo = S.StockNo
GROUP BY P.PONo ;
Get the Purchase Order and Line Item Data for those
LineItems that Use a Stock Item Identified by a Specific Stock
Number
SELECT P.PONo, P.CustNo,
L.StockNo, L.LineItemNo, L.Quantity, L.Discount
FROM PurchaseOrder_reltab P,
LineItems_reltab L
WHERE P.PONo = L.PONo
AND L.StockNo = 1004 ;
Update the Quantity for Purchase Order 1001 and Stock Item 1534
UPDATE LineItems_reltab
SET Quantity = 20
WHERE PONo = 1001
AND StockNo = 1534 ;
DELETE
FROM PurchaseOrder_reltab
WHERE PONo = 1001 ;
An object type,
Compiled by Biruk M. 14
Object table
o Having defined an object type we can create object tables of this type.
Inheritance
o Between object types there is an inheritance relation just like in the object-
oriented programming languages - achieved by UNDER operator.
o For example:
CREATE TYPE Person
AS OBJECT (
First VARCHAR2(50),
Last VARCHAR2(50)) NOT FINAL;
/
a. StockItem objtype
CREATE TYPE StockItem_objtyp AS OBJECT (
StockNo NUMBER,
Price NUMBER,
TaxRate NUMBER
)
b. Customer objtype
CREATE TYPE Customer_objtyp AS OBJECT (
CustNo NUMBER,
CustName VARCHAR2(200),
Address_obj Address_objtyp,
PhoneList_var PhoneList_vartyp,
Methods? )
Compiled by Biruk M. 15
Phonelist is an array:
CREATE TYPE PhoneList_vartyp AS VARRAY(10) OF VARCHAR2(20);
Address is an objectType:
CREATE TYPE Address_objtyp AS OBJECT (
Street VARCHAR2(200),
City VARCHAR2(200),
State CHAR(2),
Zip VARCHAR2(20)
)
Compiled by Biruk M. 16
d. LineItem_objtyp
CREATE TYPE LineItem_objtyp AS OBJECT (
LineItemNo NUMBER,
Stock_ref REF StockItem_objtyp,
Quantity NUMBER,
Discount NUMBER
)
Generally, you can think of the relationship between the "objects" and "object
tables" in the following way:
o Classes, which represent entities, map to object tables
o Attributes map to columns
o Objects map to rows
Viewed in this way, each object table is an implicit type whose objects (specific
rows) each have the same attributes (column values). The creation of explicit
user-defined datatypes and object tables introduces a new level of functionality.
syntax
o CREATE TABLE Customer_objtab OF Customer_objtyp (CustNo PRIMARY
KEY) OBJECT ID PRIMARY KEY ;
Compiled by Biruk M. 17
o CREATE TABLE Stock_objtab OF StockItem_objtyp (StockNo PRIMARY
KEY)OBJECT ID PRIMARY KEY ;
Compiled by Biruk M. 18
o Line items
Compiled by Biruk M. 19