Dbms 1&2
Dbms 1&2
Dbms 1&2
1.Database-System Application
Q:What are the application areas of database?
1
This leads to waste of storage space.
For example both current and savings account may contain the
address of a customer. If we need to change any of the data, then we
need to change the data at all copies. If not, this will lead to inconsistency.
Data isolation.
Since all the datas are isolated from each other in different files, writing
new application programs to retrieve the appropriate data is difficult.
Integrity problems.
The data values stored in the database must satisfy certain types of
consistency constraints.
constraints like “bank balance for savings account should not fall below
Rs.1000”,”Account number must be not null” are difficult to implement
when new customers are added .
Atomicity problems.
A computer system, like any other device, is subject to failure. In many
applications, it is crucial that, if a failure occurs, the data be restored to the
consistent state that existed prior to the failure.
That is, the funds transfer must be happen in its entirety(fully) or not at all.
It is difficult to ensure atomicity in a conventional file-processing system.
Concurrent-access anomalies.
Many systems allow multiple users to update the data simultaneously.
2
debit the account balance (by say Rs 500 and Rs100, respectively) of
Account A almost exactly the same time, the result of the concurrent
execution of reading balance may leave the balance in an incorrect (or
inconsistent) state.
Depending on which one writes the value last, the account balance of
department A may contain either Rs.9500 or Rs.9900, rather than the
correct value of Rs.9400.
Security problems.
Not every user of the database system should be able to access all the
data.
View of Data
A database system is a collection of interrelated data and a set of programs that
allow users to access and modify these data.
A major purpose of a database system is to provide users with an abstract view
of the data. That is, the system hides certain details of how the data are stored
and maintained.
Data Abstraction
. The database system hides certain information of how the data are stored and
maintained.
To simplify the user interaction with the system, developers hides complexity in
different levels
Physical level.
The lowest level of abstraction describes how the data are actually stored. The
physical level describes complex low-level data structures in detail.
Logical level.
The next-higher level of abstraction describes what data are stored in the
database, and what relationships exist among those data.
The logical level describes the entire database in terms of simple structures.
The user of the logical level does not need to be aware of the complexity at
physical level.
This is referred to as physical data independence.
View level.
The highest level of abstraction describes only part of the entire database..
Many users of the database system do not need al this information; instead,
3
they need to access only a part of the database.
The view level of abstraction exists to simplify their interaction with the system.
The system may provide many views for the same database.
. For example, we may describe a record as follows:1
type instructor = record
ID :char (5);
name : char (20);
dept name : char (20);
salary : numeric (8,2);
end;
This code defines a new record type called instructor with four fields.Each field
has a name and a type associated with it.
At the physical level, an instructor, department, or student record can be de-
scribed as a block of consecutive storage locations.
At the logical level, each such record is described by a type definition,
At the view level, several views of the database are defined, and a database user
sees some or all of these views.
Instances and Schemas
The collection of information stored in the database at a particular moment
is called an instance of the database.
A database may also have several schemas at the view level, sometimes
called sub schemas, that describe different views of the database.
.
Q:Explain the different data models
Data Models
Underlying the structure of a database is the data model:
There are a number of different data models that we shall cover in the text.The
4
data models can be classified into four different categories:
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 known as relations.
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 in record based model.
The relational data model is the most widely used data model.
Entity-Relationship Model.
The entity-relationship (E-R) data model uses a collection of basic objects,
called entities, and relationships among these objects.
Object-Based DataModel.
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.
5
languages..
I.Data-Manipulation Language
A data-manipulation language (DML) is a language that enables users to access
or manipulate data.
The types of access are:
• Retrieval of information stored in the database
• Insertion of new information into the database
• Deletion of information from the database
• Modification of information stored in the database
There are basically two types:
• Procedural DMLs require a user to specify what data are needed and how to get
those data.
• Decla rative DMLs (also referred to as nonprocedural DMLs) require a user to
specify what data are needed without specifying how to get those data.
II.Data-Definition Language
We specify a database schema by Data Definition Language (DDL).
Domain Constraints.
A domain of possible values must be associated with every attribute
They are tested easily by the system whenever a new data item is entered
into the database.
Referential Integrity.
There are cases where we wish to ensure that a value that appears in one
relation for a given set of attributes also appears in a certain set of
attributes in another relation (referential integrity).
For example, the department listed for each course must be one that
actually exists.
More precisely, the dept name value in a course record must appear in the
dept name attribute of some record of the department relation.
Assertions.
An assertion is any condition that the database must always satisfy.
And conditions like “Every department must have at least five courses ”can
be expressed as an assertion.
Authorization.
We can differentiate the users by the type of access they are permitted on
various data values in the database.
Database schema
Database schema is the logical design of the database.
Relation schema represents the logical design of the relation.
7
Schema of banking database
Branch_schema(branch_name,branch_city,assets)
Customer_schema(customer_name,customer_street,customer_city)
Loan_schema(loan_number,branch_name,amount)
Borrower_schema(customername,loan_number)
Account_schema(account_number,branch_name,balance)
Depositor_schema (customer_name,account_number)
From the above schema ,the depositor schema describes the association
between customers and accounts .
The borrower schema describes the association between customers and loan.
Basic structure
Attributes:In Relational model we refer to the coloumn headers of a table as
attributes
Domain:set of permitted values for an attributes called as domains
Relation:Table name is mathematically referred as relation in Relational
model
Tuple:Row is referred as tuple in relational model
Keys
No two values in a relation are allowed to have exactly the same value for
two attributes. Keys ensures this.There are different types of keys ,
1.Super key
Set of one or more attributes taken collectively ,allow us to identify uniquely
a tuple
Example
{customer_id}
{customer_id,customer_name}
{cutomer_id,customer_name,street}
Candidate key
Minimal super keys are called as candidate key. ie Super keys for
which no proper subset is a super key.
Example
8
{customer_id}
Only customer id is enough to identify the tuples uniquely.
Candidate key is also called as Primary key
2.Foreign key
A relation schema ,say r1 ,may include attributes which are the
primary key of another relation schema ,say r2.This attribute is called
foreign key.
Then the relation r1 is called the referencing relation and r2 is called
the referenced relation.
Example
account
Account_number
Branch_name
Balance
depositor
Customer_name
Account number
Relational algebra :
9
Definition:
Select
Project
Union
Set different
Cartesian product
Rename
Syntax
σp(r)
Where σ stands for selection predicate and r stands for relation.
10
σbranch_name = "nagamalai" (loan)
Output − Selects tuples from loan where branch is 'nagamalai'.
Example
∏loan_number, amount(loan)
Loan_number amount
L1 2000
Syntax
rUs
∏customername(borrower) U ∏customername(depositor)
Customer_name
Ravi
Priya
12
Rama
Example
∏customername(borrower) - ∏customername(depositor)
Customer_name
Ravi
Priya
πcutomer_name,branch_name(borrower X loan)
13
This expression takes cartesian product between two tables borrower
and loan and then applies the projection operation.
Ravi kalavasal
Ravi nagamalai
Shree kalavasal
Shree nagamalai
ρ x (E)
Example
ρ newloan (∏branch_name, amount(loan))
14
in relational algebra a deletion is expressed in terms of set difference
operation
r←r-E
where r is a relation and E is a relational- algebra query.
Example
delete the records from the relation “loan” where branch name is
Nagamalai.
loan←loan- σbranch_name = "Nagamalai"(loan)
Insertion
r←r U E
Example
loan←loan U {12,”nagamalai”,90000}
Updating
We can change a value in a tuple by updation operatin
This can be done by
∏F1,F2,……Fn(r)
15