|
|
1.)
Explain the role of database administrator The
database which are corporate or enterprise wide are typically important &
complex enough. This task of designing and maintaining the database in entrusted to a
Professional called database administrator. The following are the critical tasks of DBA. ·
Data availability & recovery
from failure. The DBA must take steps to ensure that
if the system fails, users can continue to access as much as uncorrupted data as possible
.he must try to work to restore to the data for a consistent state. The DBMS provides s/w
support to these ,but DBA is responsible for
its implementation to backup the data periodically & maintain logs of system
activities. ·
Database tuning The
users need are likely to change with time , there queries tend to change with time
.The DBA is responsible to modify the DB, i.e he has to make changes in the conceptual
& the physical schema .This is to be done to ensure adequate performance as
requirements change.
2.)
Explain with a suitable example, converting an E-R diagram into a table. Convert ER
diagram to relational model (DB tables):
·
Each entity: a table (relation), primary key
·
Each
relationship either:
o
a table, containing the primary keys of the relevant entities (foreign keys)
o
represent by making the primary key of one
table the foreign key of another ·
Each attribute: a column in a table
|
| Generalization hides differences and emphasizes
similarities. | |
| Distinction made through attribute
inheritance. | |
| Attributes of higher-level entity are inherited
by lower-level entities. | |
| Two methods for conversion to a table form: |
| Create a table for the high-level entity, plus
tables for the lower-level entities containing also their specific attributes. | |
| Create only tables for the lower-level entities.
|
Aggregation:
It is an abstraction concept for building
composite objects from their component objects.
It is used when we have to model a relationship
involving entity sets and a relationship set.
It allows us to treat a relationship set as an entity set
for purposes of participation in other relationships.
The E-R model cannot express relationships among
relationships.
When would we need such a thing?
Consider a DB with information about employees
who work on a particular project and use a number of machines doing that work. We get the
E-R diagram shown in the following Figure 1:

Figure 1: E-R diagram with redundant
relationships
Relationship sets work and uses could be
combined into a single set. However, they shouldn't be, as this would obscure the logical
structure of this scheme.
The solution is to use aggregation.
An abstraction through which
relationships are treated as higher-level entities.
For our example, we treat the relationship set
work and the entity sets employee and project as a higher-level entity set called work.
Figure 2 : shows the
E-R diagram with aggregation.
Figure 2: E-R diagram with aggregation
Transforming an E-R diagram with aggregation
into tabular form is easy. We create a table for each entity and relationship set as
before.
The table for relationship set uses contains a
column for each attribute in the primary key of machinery and work.
12.)
Compare SQL and QBE
QBE and SQL:
·
QBE language is
important because it is one of the first graphical query languages with minimum syntax
developed for database systems.
·
QBE differs from SQL
in that the user
does not have to specify a structured query explicitly; rather, the query is formulated by
filling in templates of relations displayed on the monitor screen.
·
The user does not
have to follow any rigid syntax rules for query specification in the QBE.
·
QBE is related to the
domain relational calculus whereas SQL is based to a greater extent on the tuple relational calculus.
·
QBEs original specification is shown to be
relationally complete.
·
QBE does not use the
linear style of SQL; rather, it is a two-dimensional language,
because users specify a query moving around the full area of the screen.
13.)
Explain about Domain Calculus expression.
Solution:
The
Domain Relational Calculus
Domain
variables take on values from an attribute's domain, rather than values for an entire tuple
1. An expression is of the form
![]()
where the
represent domain variables, and
is
a formula.
2. An atom in the domain relational calculus is of
the following forms
o
where
is a
relation on
attributes, and
, are domain variables or constants.
o
, where
and
are domain variables, and
is a comparison operator.
o
, where c is a constant.
3. Formulae are built up from atoms using the following
rules:
o
An atom is a formula.
o
If
is
a formula, then so are
and
.
o
If
and
are formulae, then so are
,
and
.
o
If
is a formula where x is a domain variable, then so
are
and
.
14.)
Write short notes on a)Entities and attributes b)Strong and
Weak Entities c)Cross products and Joins
Solution:
a.)
An
entity is an object that exists and is distinguishable from other objects. For instance,
John Harris with S.I.N. 890-12-3456 is an entity, as he can be uniquely identified as one
particular person in the universe.
An
entity may be concrete (a person or a book, for
example) or abstract (like a holiday or a
concept).
An
entity is represented by a set of attributes.
E.g.
name, S.I.N., street, city for ``customer'' entity.
The
domain of the attribute is the set of permitted values (e.g. the telephone number must be
seven positive integers).
Formally,
an attribute is a function which maps an entity set into a domain.
Every
entity is described by a set of (attribute, data value) pairs.
There
is one pair for each attribute of the entity set.
E.g.
a particular customer entity is described by the set {(name, Harris), (S.I.N.,
890-123-456), (street, North), (city,
b.)
Strong
vs. Weak Entities
A
Strong Entity does not depend on anything else in the database for its existence. It contains its own primary key.
A
Weak Entity depends on some related entity for its existence. It has no candidate keys without including the
primary key of the entity it depends on.
Strong
vs. Weak Example
Employee
( empNo PK, fname,
lname salary,
) HAS Child (fname)
Employee
is strong (with empNo as primary key)
Child
is weak - many children may be called Jennifer, but only one Jennifer is the
daughter of employee 24901.
15.)
Explain different levels of abstraction in a DBMS.. What is
data independence? Explain different types of Data Independence
1. The major purpose of a database system is to
provide users with an abstract view of the system.
The system hides certain details of how data is
stored and created and maintained
Complexity should be hidden from database users.
2. There are several levels of abstraction:
1. Physical Level:
§
How the data are
stored.
§
E.g. index, B-tree,
hashing.
§
Lowest level of
abstraction.
§
Complex low-level
structures described in detail.
2. Conceptual Level:
§
Next highest level of
abstraction.
§
Describes what
data are stored.
§
Describes the
relationships among data.
§
Database
administrator level.
3. View Level:
§
Highest level.
§
Describes part
of the database for a particular group of users.
§
Can be many different
views of a database.
§
E.g. tellers in a
bank get a view of customer accounts, but not of payroll data.
Figure illustrates the three levels.
Figure: The three levels of data abstraction
Data
The
ability to modify a scheme definition in one level without affecting a scheme definition
in a higher level is called data independence.
There
are two kinds:
Physical
data independence
The
ability to modify the physical scheme without causing application programs to be
rewritten. Modifications at this level are usually to improve performance.
Logical
data independence
The
ability to modify the conceptual scheme without causing application programs to be
rewritten. Usually done when logical structure of database is altered
.
Logical
data independence is harder to achieve as the application programs are usually heavily
dependent on the logical structure of the data. An analogy is made to abstract data types
in programming languages.
16.)
Explain TRC and DRC with examples. List two reasons why null values are introduced into
databases. Explain nested subqueries in SQL.
Solution:
Relational
calculus is an alternative to relational algebra. The calculus
is nonprocedural, or declarative, in that it allows
us to describe the set of answers without being explicit about how they
should be computed. Relational calculus has had a big influence on the design of
commercial query languages such as SQL and, especially, Query-by-Example
(QBE).
The variant of
the calculus we present in detail is called the tuple
relational calculus (TRC).
Variables in TRC take on tuples as values. In
another variant, called the domain relational calculus
(DRC), the variables range over field values. TRC has had
more of an influence on SQL, while DRC has strongly influenced QBE.
Tuple Relational
Calculus
A tuple variable is a variable that takes on tuples of a
particular relation schema as
values. That is, every value assigned to a given tuple
variable has the same
number and type of fields. A tuple relational calculus query
has the form { T p(T) }, where T is a tuple variable and p(T) denotes a formula that describes T\
we will shortly define formulas and queries rigorously. The result of this query
is the set of all tuples t for which the formula p(T) evaluates to true with T
t. The language for writing formulas p(T) is thus
at the heart of TRC and
essentially a simple subset of first-order logic. As a simple example, consider the following query.
(Qll) Find all sailors with a rating above 7.
{S | S E Sailors^ S.rating
> 7}
When this query
is evaluated on an instance of the Sailors relation, the tuple
variable
S is instantiated successively with each tuple, and the
test S.rating>7 is applied. The
answer contains those instances of S that pass this test. On instance 53 of
Sailors, the answer contains Sailors tuples with sid 31, 32, 58,
71, and 74.
Syntax of
TRC Queries
We now define
these concepts formally, beginning with the notion of a formula. Let Rel be a relation name, R and S be tuple variables, a be an attribute of R, and b be an
attribute of S. Let op denote an operator in the set {<, >, = , <= , >=, !=} An
atomic formula is one of the following:
R
R.a op S.b
R.a op constant, or
constant op R.a
A formula is
recursively defined to be one of the following, where p and q are themselves
formulas and p(R) denotes a formula in which the variable R appears:
Any atomic formula
Not p, p ^
q, p V q, or p implies q
There exists R
such that p(R) , where K is a tuple variable
For all
R(p(R)), where R is a tuple variable
The quantifiers there exists and for all are said to bind the variable R.. A variable is
said to be free in a formula or sub formula (a
formula contained in a larger
formula) if the (sub)formula does not contain an occurrence of
a quantifier
that binds it.
Every variable
in a TRC formula appears in a sub formula that is
atomic, and every relation schema specifies a domain for each field; each variable
in a TRC formula has a well-defined domain from
which values for the variable are drawn. Informally, an
atomic
formula R
For
example :
Find the names and ages of sailors with a rating
above 7.
{P
/ there exists an S Sailors(S.rating > 7 ^ P.name =S.sname ^ P.age = S.age)}.
Domain Relational Calculus
A domain
variable is a variable that ranges over the values in the domain of some attribute (e.g., the variable can be
assigned an integer if it appears in an attribute whose domain is the set of integers). A
DRC query has the form {<x1,X2,.
xn>/ p(<x1,X2,..,xN>)}, where each Xj is either a domain variable or a constant and
p(<x1,x2,
,xn>) denotes a DRC formula whose only
free variables are the variables among the xi, 1 < i
< n. The result of this query is the set of all tuples
(x1,x2,..., xn) for
which the formula evaluates to true.
A
DRC formula is defined in a manner very similar to the definition of a TRC formula.
The main difference is that the variables are now domain variables. Let
op denote an operator in the set {<,>,=,<, >, ^}
and let X and Y be domain
variables. An atomic formula in DRC is one of the following:
(x1,x2,
.xn) E Rel, where Rel is a relation with n attributes; each xi,
1
< i < n is
either a variable or a constant
X
op Y
X
op
constant, or constant op X
A
formula is recursively defined to be one of the following, where p and q are
themselves formulas and p(X) denotes a formula in which the variable A' appears:
Any atomic formula
Not p, p ^
q, p V q, or p implies q
There exists R
such that p(R) , where R is a domain variable
For all
R(p(R)), where R is a domain variable
Examples of DRC Queries
Find all sailors with a rating above 7.
{{I, N, T, A)
/ {I, N, T, A)
E Sailors ^T > 7}
17.)
Differentiate between binary and ternary relationships
A . 
Policy as an entity set.
Consider the E-R diagram . It models a situation in which an employee can
own several policies ,each policy can be owned by several employees, and each dependent
can be covered by several policies.
Suppose
that we have the following additional requirements :
·
A
policy cannot be owned jointly by two or more requirements.
·
Every policy must be owned by some employee.
·
Dependents is a weak entity set
, and each dependent entity is uniquely identified by taking pname
in conjunction with the policyid of a policy entity.
The first requirement suggests that we impose a key
constraint on polices with respect to covers, but this constraint has the unintended side
effect that a policy can cover only one dependent. The second requirement suggests that we impose a total
participation constraint on policies. This solution is acceptable if each policy covers
at least one dependent . the third requirement forces us to
introduce an identifying relationship that is binary .
The
best way to model this situation is to use two binary relationships,

Policy revisited.
As a
typical example of a ternary relation ship, consider entity sets parts, suppliers, and departments , and a relationship set contracts that involves all of
them . A contract specifies that a supplier will supply a part to a department. This
relation ship can not be adequately captured by a collection of binary relationships. With
binary relationship , we can denote that a supplier can supply certain parts
that a department needs some
parts ,or a department deals with
a certain supplier. No combination of these
relationships express the meaning of a contract adequately, for at least two reasons :
·
The facts that supplier s can supply part p, that department D needs part P , and that D will
buy from S do not necessarily imply that department D indeed buys part P from suppliers S.
·
We cannot represent the qty attribute of a
contract cleanly.
19.)
Construct an ER digrm for a cr
insurance company that has a set of customers, each of whom owns one or more cars. Each
car has associated with it zero to any number of recorded accidents.
Solution:

20.)
Describe the extended ER features.
Solution:










21.)Draw the ER diagram for the banking
Solution:

Let us
assume that the bank has two types of customers
1)
Depositors
Fixed Account and Current Savings
2)
Borrowers Who
take loan on interest.
Constraints:
·
Each customer has a
unique customer_id.
·
Has to have an account
either fixed or current savings if it is a depositor.
·
Fixed account holders
have a unique account_no, amount, and duration of the fixed
deposit.
·
Current savings
account holders have a unique account_no and interest.
·
Borrowers have a
unique loan_id, amount, duration(of
payback) and interest.
22.)
Describe fundamental operations of relational algebra with examples. Discuss natural join
with an example.
Solution:
The Select Operation
Select selects tuples
that satisfy a given predicate. Select is denoted by a lowercase Greek sigma (
), with the predicate appearing as a subscript. The argument
relation is given in parentheses following the
.
For example, to select tuples
(rows) of the borrow relation where the branch is ``SFU'', we would write
![]()
Let Figure 1 be the borrow
and branch relations in the banking example.
Figure 1: The borrow
and branch relations.
The new relation created as the result of this
operation consists of one tuple:
.
We allow comparisons using =,
,
<,
, > and
in the
selection predicate.
We also allow the logical connectives
(or) and
(and). For
example:
![]()
Figure 2: The client relation.
Suppose there is one more relation, client,
shown in Figure 2, with
the scheme
![]()
we might write
![]()
to find clients who
have the same name as their banker.
The Project Operation
Project copies its argument relation for
the specified attributes only. Since a relation is a set, duplicate rows are
eliminated.
Projection is denoted by the Greek capital
letter pi (
). The attributes to be copied appear as subscripts.
For example, to obtain a relation showing
customers and branches, but ignoring amount and loan#, we write
![]()
We can perform these operations on the relations
resulting from other operations.
To get the names of customers having the same
name as their bankers,
![]()
Think of select as taking rows of a
relation, and project as taking columns of a relation.
The Cartesian Product
Operation
The cartesian
product of two relations is denoted by a cross (
), written
![]()
The result of
is a new
relation with a tuple for each possible pairing of tuples from
and
.
In order to avoid ambiguity, the attribute names
have attached to them the name of the relation from which they came. If no ambiguity will
result, we drop the relation name.
The result
is a very large
relation. If
has
tuples, and
has
tuples, then
will have
tuples.
The resulting scheme is the concatenation of the
schemes of
and
, with relation names added as mentioned.
To find the clients of banker Johnson and the
city in which they live, we need information in both client and customer
relations. We can get this by writing
![]()
However, the customer.cname
column contains customers of bankers other than Johnson. (Why?)
We want rows where client.cname
= customer.cname. So we can write
![]()
to get just these tuples.
Finally, to get just the customer's name and
city, we need a projection:
![]()
The Rename Operation
The rename operation solves the problems that occurs with naming when performing the cartesian product of a relation with itself.
Suppose we want to find the names of all the
customers who live on the same street and in the same city as Smith.
We can get the street and city of
![]()
To find other customers with the same
information, we need to reference the customer relation again:
![]()
where
is
a selection predicate requiring street and ccity
values to be equal.
Problem: how do we distinguish between
the two street values appearing in the Cartesian product, as both come from a customer
relation?
Solution: use the rename operator, denoted by the Greek letter rho
(
).
We write
![]()
to get the relation
under the name
of
.
If we use this to rename one of the two customer
relations we are using, the ambiguities will disappear.
![]()
The Union Operation
The union operation is denoted
as in set theory. It returns the union (set union) of two
compatible relations.
For a union operation
to
be legal, we require that
o
and
must have the same number of attributes.
o
The domains of the
corresponding attributes must be the same.
To find all customers of the SFU branch, we must
find everyone who has a loan or an account or both at the branch.
We need both borrow and deposit
relations for this:
![]()
As in all set operations, duplicates are
eliminated, giving the relation of Figure 3(a).
Figure 3: The union and set-difference
operations.
The Set Difference Operation
Set difference is denoted by the minus sign (
). It finds tuples that are in one
relation, but not in another.
Thus
results in a
relation containing tuples that are in
but
not in
.
To find customers of the SFU branch who have an
account there but no loan, we write
![]()
The result is shown in Figure 3(b).
We can do more with this operation. Suppose we
want to find the largest account balance in the bank.
Strategy:
o
Find a relation
containing the balances not the largest.
o
Compute the set
difference of
and the deposit relation.
To find
, we write
![]()
This resulting relation contains all balances
except the largest one. (See Figure 4(a)).
Now we can finish our query by taking the set
difference:
![]()
Figure 4(b) shows the result.
Figure 4: Find the largest account balance in
the bank.
The Natural Join Operation
Often we want to simplify queries on a cartesian product.
For example, to find all customers having a loan
at the bank and the cities in which they live, we need borrow and customer
relations:
![]()
Our selection predicate obtains only those tuples pertaining to only one cname.
This type of operation is very common, so we
have the natural join, denoted by a
sign. Natural
join combines a cartesian product and a selection into one
operation. It performs a selection forcing equality on those attributes that appear in
both relation schemes. Duplicates are removed as in all relation operations.
To illustrate, we can rewrite the previous query
as
![]()
The resulting relation is shown in Figure 5
Figure 5: Joining borrow
and customer relations.
We can now make a more formal definition of
natural join.
o
Consider
and
to be sets of attributes.
o
We denote attributes
appearing in both relations by
.
o
We denote attributes
in either or both relations by
.
o
Consider two
relations
and
.
o
The natural join of
and
, denoted by
is a relation on scheme
.
o
It is a projection
onto
of a selection on
where the predicate requires
for each attribute
in
.
Formally,
![]()
where
.
To find the assets and names of all branches
which have depositors living in
![]()
Note that
is
associative.
To find all customers who have both an account
and a loan at the SFU branch:
![]()
This is equivalent to the set intersection
version we wrote earlier. We see now that there can be several ways to write a query in
the relational algebra.
If two relations
and
have no attributes in common, then
, and
.
23.)Explain various built in functions of SQL.
Solution:
Built-In
Functions
PL/SQL
provides more than 75 powerful functions to help you manipulate data. These built-in
functions fall into the following categories:
1)
error-reporting
2)
number
3)
character
4)
conversion
5)
date
6)
miscellaneous
Table 1
shows the functions in each category.
You can use
all the functions in SQL statements except the error- reporting functions SQLCODE and
SQLERRM. Also, you can use all the functions in procedural statements except the
miscellaneous functions DECODE, DUMP, and VSIZE.
Note: The
SQL group functions AVG, MIN, MAX, COUNT, SUM, STDDEV, and VARIANCE are not built into
PL/SQL. Nevertheless, you can use them in SQL statements (but not in procedural
statements).
Error |
Number |
Character
|
Conversion
|
Date |
Misc |
SQLCODE |
ABS |
ASCII |
CHARTOROWID |
ADD_MONTHS |
DECODE |
SQLERRM |
ACOS |
CHR |
CONVERT |
LAST_DAY |
DUMP |
ASIN |
CONCAT |
HEXTORAW |
MONTHS_BETWEEN
|
GREATEST |
|
ATAN |
INITCAP |
RAWTOHEX |
NEW_TIME |
GREATEST_LB |
|
ATAN2 |
INSTR |
ROWIDTOCHAR |
NEXT_DAY |
LEAST |
|
CEIL |
INSTRB |
TO_CHAR |
ROUND |
LEAST_LB |
|
LENGTH |
TO_DATE |
SYSDATE |
NVL |
||
COSH |
LENGTHB |
TO_LABEL |
TRUNC |
UID |
|
EXP |
LOWER |
TO_MULTI_BYTE
|
USER |
||
FLOOR |
LPAD |
TO_NUMBER |
USERENV |
||
LN |
LTRIM |
TO_SINGLE_BYTE
|
VSIZE |
||
LOG |
NLS_INITCAP |
||||
MOD |
NLS_LOWER |
||||
POWER |
NLS_UPPER |
||||
ROUND |
NLSSORT |
||||
SIGN |
REPLACE |
||||
SIN |
RPAD |
||||
SINH |
RTRIM |
||||
SQRT |
SOUNDEX |
||||
TAN |
SUBSTR |
||||
TANH |
SUBSTRB |
||||
TRUNC |
TRANSLATE |
||||
UPPER |
Table 1. Built-in
Functions