Infosys Dbms Question Answer
Infosys Dbms Question Answer
relation R which is referred in the relation S is called the foreign key in the
relation S and
referenced key in the relation R. The relation R is also called as parent table and
relation S
is also called as child table.
For example:
STUDENT
Enrl No
Roll No Name
City Mobile
11 17 Ankit Vats Delhi 9891663808
15 16 Vivek Rajput Meerut 9891468487
6 6 Vanita Punjab
33 75 Bhavya Delhi 9810618396
GRADE
Roll No Course Grade
6CA
17 VB C
75 VB A
6 DBMS B
16 C B
_ Roll No is the primary key in the relation STUDENT and Roll No + Course is the
primary key of the relation GRADE.
_ Enrl No and Roll No are the candidate keys of the relation STUDENT.
_ Roll No in the relation GRADE is a foreign key whose values must be one of
those
of the relation STUDENT.
Q.4 Differentiate between logical database design and physical database design.
Show how
this separation leads to data independence. (7)
Ans:
Basis Logical Database Design Physical Database Design
Task Maps or transforms the conceptual
schema (or an ER schema) from the
high-level data model into a
relational database schema.
The specifications for the stored
database in terms of physical storage
structures, record placement, and
indexes are designed.
Choice of
criteria
The mapping can proceed in two
stages:
_ System-independent mapping
but data model-dependent
_ Tailoring the schemas to a
specific DBMS
The following criteria are often used
to guide the choice of physical
database design options:
_ Response Time
_ Space Utilization
_ Transaction Throughput
Result DDL statements in the language of
the chosen DBMS that specify the
conceptual and external level
schemas of the database system. But
(ii) Get the employee numbers of employees who do not work on the COMP123
project.
Ans:
(i) Tuple Calculus:
{t[Emp#] | t ASSIGNED_TO "p (p PROJECT _ $u (u ASSIGNED_TO
p[Project#] = u[Project#] t[Emp#] = u[Emp#]))}
Domain Calculus:
{e | $p (<p, e> ASSIGNED_TO "p1 (<p1, n1, c1> PROJECT
_ <p1, e> ASSIGNED_TO))}
(ii) Tuple Calculus:
{t[Emp#] | t ASSIGNED_TO $u (u ASSIGNED_TO
u[Project#] = COMP123 t[Emp#] = u[Emp#] )}
Domain Calculus:
{e | $p (<p, e> ASSIGNED_TO "p1, e1 (<p1, e1> ASSIGNED_TO
p1 COMP123 e1 e))}
Q.6 What is ODBC? How does Oracle act as ODBC and give examples of front
end uses with
ODBC. (7)
Ans:
ODBC Open DataBase Connectivity (ODBC) enable the integration of SQL with
a
general-purpose programming language. ODBC expose database capabilities in a
standardized way to the application programmer through an application
programming
interface (API). Using ODBC, an application can access not just one DBMS but
several
different ones simultaneously.
ODBC achieve portability at the level of the executable by introducing an extra
level of
indirection. All direct interaction with a specific DBMS happens through a
DBMSspecific
driver. A driver is a software program that translates the ODBC calls into
DBMSspecific
calls. Drivers are loaded dynamically on demand since the DBMSs the
application is going to access are known only at run-time. Available drivers are
registered
with a driver manager. The Oracle database driver translates the SQL commands
from the
application into equivalent commands that the Oracle DBMS understands and
takes the
result from the DBMS and translate into equivalent form for the application.
Example: Let there be a DSN named EMPLOYEE through, which we want to
access the
Oracle database in Visual Basic.
Dim CN As New ADODB.Connection
Dim RS As New ADODB.Recordset
CN.Open DSN=employee, scott, tiger
RS.Open Select * From Emp, CN
Q.7 Define the five basic operators of relational algebra with an example each.
(7)
Ans: Five basic operators of relational algebra are:
1. Union () - Selects tuples that are in either P or Q or in both of them. The
duplicate tuples are eliminated.
R=PQ
2. Minus () - Removes common tuples from the first relation.
R=PQ
3. Cartesian Product or Cross Product () - The cartesian product of two
relations is the concatenation of tuples belonging to the two relations and
consisting of
all possible combination of the tuples.
R=PQ
For Example:
P:
Q:
ID Name
ID
Name
101 Jones
100 John
103 Smith
104 Lalonde
104 Lalonde
R=PQR=PQ
ID Name ID Name
100 John 101 Jones
101 Jones 103 Smith
103 Smith
104 Lalonde
R=PQ
P.ID P.Name Q.ID Q.Name
101 Jones 100 John
101 Jones 104 Lalonde
103 Smith 100 John
103 Smith 104 Lalonde
104 Lalonde 100 John
104 Lalonde 104 Lalonde
4. Projection (p) - The projection of a relation is defined as a projection of all its
tuples
over some set of attributes, i.e., it yields a vertical subset of the relation. It is
used to
Q.8 Explain entity integrity and referential integrity rules in relational model.
Show how
these are realized in SQL. (7)
Ans:
Entity Integrity Rule No primary key value can be null.
Referential Integrity Rule In referential integrity, it is ensured that a value
that appears
in one relation for a given set of attributes also appears for a certain set of
attributes in
another relation.
In SQL, entity integrity and referential integrity rules are implemented as
constraints on
the relation called as primary key constraint and reference key constraint
respectively.
These constraints can be specified with relation at the time of creation of the
relations or
after the creation of the relations by altering the definition of the relations. For
example:
CREATE TABLE DEPT
(DEPTNO NUMBER PRIMARY KEY,
DNAME VARCHAR2(15));
CREATE TABLE EMP
(EMPNO NUMBER PRIMARY KEY
ENAME VARCHAR2(15),
JOB VARCHAR2(10),
DEPTNO NUMBER REFERENCES DEPT(DEPTNO));
Q.9 What are the advantages of embedded query language? Give an example of
a embedded
SQL query. (7)
Ans:
Embedded query language SQL can be implemented in two ways. It can be
used
Temporary tables exists solely for a particular session, or whose data persists for
the
duration of the transaction. The temporary tables are generally used to support
specialized
rollups or specific application processing requirements. Unlike a permanent table,
a space
is not allocated to a temporary table when it is created. Space will be
dynamically
allocated for the table as rows are inserted. The CREATE GLOBAL TEMPORARY
TABLE command is used to create a temporary table in Oracle.
CREATE GLOBAL TEMPORARY TABLE <table_name> (
<columns details>
) ON COMMIT {PRESERVE|DELETE} ROWS;
Q.14 Draw and explain the three level architecture of the database system. (7)
Ans:
A DBMS provides three levels of data is said to follow three-level architecture.
The goal
of the three-schema architecture is to separate the user applications and the
physical
database. The view at each of these levels is described by a schema. The
processes of
transforming requests and results between levels are called mappings. In this
architecture,
schemas can be defined at the following three levels:
_ External Level or Subschema It is the highest level of database
abstraction where
only those portions of the database of concern to a user or application program
are
included. Any number of user views (some of which may be identical) may exist
for a
given global or conceptual view. Each external view is described by means of a
schema
called an external schema or subschema.
Comparisons shall be based on one or more sort keys extracted from each line of
input
(or, if no sort keys are specified, the entire line up to, but not including, the
terminating
<newline>), and shall be performed using the collating sequence of the current
locale.
Q.16 Describe a method for direct search? Explain how data is stored in a file so
that direct
searching can be performed.
Ans: For a file of unordered fixed length records using unspanned blocks and
contiguous allocation, it is straight forward to access any record by its position in
the file.
If the file records are numbered 0,1,2,---,r-1 and the records in each block are
numbered
0,1,---bfr-1; where bfr is the blocking factor, then ith record of the file is located
in block
[(i/bfr)] and is the (I mod bfr)th record in that block. Such a file is often called a
relative or
direct file because records can easily be accessed directly by their relative
positions.
Accessing a record based on a search condition; however, it facilitates the
construction of
access paths on the file, such as the indexes.
Q17 Explain the integrity constraints: Not Null, Unique, Primary Key with an
example each.
Is the combination Not Null, Primary Key a valid combination. Justify. (7)
Ans: Not Null Should contain valid values and cannot be NULL.
Unique An attribute or a combination of two or more attributes must have a
unique
value in each row. The unique key can have NULL values.
Primary Key It is same as unique key but cannot have NULL values. A table
can have
at most one primary key in it.
For example:
STUDENT
Roll No Name
City Mobile
17 Ankit Vats Delhi 9891663808
16 Vivek Rajput Meerut 9891468487
6 Vanita Punjab NULL
75 Bhavya Delhi 9810618396
_ Roll No is a primary key.
_ Name is defined with NOT NULL, means each student must have a name.
_ Mobile is unique.
Not Null, Primary Key is a valid combination. Primary key constraint already
includes
Not Null constraint in it but we can also add Not Null constraint with it. The use
of
Not Null with Primary Key will not have any effect. It is same as if we are using
just
Primary Key.
Q.18 Explain the followings :
(i) Nested Queries.
(ii) Cursors in SQL.
(iii) RDBMS.
(iv) View
(v) Application Programming Interface (14)
Ans: (i) Nested Queries A SELECT query can have subquery(s) in it. When a
SELECT query having another SELECT query in it, is called as nested query. Some
operations cannot be performed with single SELECT command or with join
operation.
There are some operations which can be performed with the help of nested
queries (also
referred to as subqueries). For example, we want to compute the second highest
salary:
SELECT MAX(SAL) FROM EMP WHERE SAL < (SELECT MAX(SAL) FROM EMP)
Some operations can be performed both by Join and subqueries. The Join
operation is
costlier in terms of time and space. Therefore, the solution based on subqueries
is
preferred.
(ii) Cursors in SQL An object used to store the output of a query for row-byrow
processing by the application programs. Cursors are constructs that enable the
user to
name a private memory area to hold a specific statement for access at a later
time.
Cursors are used to process multi-row result sets one row at a time. Additionally,
cursors
keep track of which row is currently being accessed, which allows for interactive
processing of the active set.
(iii) RDBMS RDBMS is a database management system (DBMS) that stores
data in
the form of relations. Relational databases are powerful because they require few
assumptions about how data is related or how it will be extracted from the
database. As a
result, the same database can be viewed in many different ways. An important
feature of
relational system is that a single database can be spread across several tables.
This differs
from flat-file databases, in which each database is self-contained in a single
table.
(iv) View A view is a relation (virtual rather than base) and can be used in
query
expressions, that is, queries can be written using the view as a relation. In other
words, a
view is a named table that is represented, not by its own physically separate
stored data,
but by its definition in terms of other named tables (base tables or views). The
base
relations on which a view is based are sometimes called the existing relations.
The
definition of a view in a create view statement is stored in the system catalog.
The syntax
to create a view is:CREATE [OR REPLACE] VIEW <view_name> [(<aliases>)] AS
<query> WITH {READ ONLY|CHECK OPTION [CONSTRAINT
<constraint_name>]};
(v) Application Programming Interface Commercial SQL implementations
take
one of the two basic techniques for including SQL in a programming language
embedded SQL and application program interface (API). In the application
program
interface approach, the program communicates with the RDBMS using a set of
functions
called the Application Program Interface (API). The program passes the SQL
statements
to the RDBMS using API calls and uses API calls to retrieve the results. In this
method,
the precompiler is not required.
Q.19 Consider the following relational schema: (7)
PERSON (SS#, NAME, ADDRESS)
CAR (REGISTRATION_NUMBER, YEAR, MODEL)
ACCIDENT (DATE, DRIVER, CAR_REG_NO)
OWNS (SS#, LICENSE)
Construct the following relational algebra queries:
(i) Find the names of persons who are involved in an accident.
(ii) Find the registration number of cars which were not involved in any accident.
Ans: (i) pNAME(PERSON) pDRIVER(ACCIDENT)
(ii) pREGISTRATION_NUMBER(CAR) pCAR_REG_NO(ACCIDENT)
Q.20 What is a key? Explain Candidate Key, Alternate Key and Foreign Key. (7)
Ans:
Key A single attribute or a combination of two or more attributes of an entity
set that is
used to identify one or more instances (rows) of the set (table) is called as key.
Candidate Key A candidate key is a minimal superkey, which can be used to
uniquely
identify a tuple in the relation.
Alternate Key All the candidate keys except primary key are called as
alternate keys.
Foreign Key Let there are two relations (tables) R and S. Any candidate key of
the
relation R which is referred in the relation S is called the foreign key in the
relation S and
referenced key in the relation R. The relation R is also called as parent table and
relation S
is also called as child table.
Q.21 What is data independence? Explain the difference between physical and
logical data
independence. (7)
Ans: Data independence is the capacity to change the schema at one level of a
database
system without having to change the schema at the next level. The threeschema
architecture allows the feature of data independence. Data independence occurs
because when the schema is changed at some level, the schema at the next
level
remains unchanged; only the mapping between the two levels is changed. Types
of
data independence are:
_ Physical Data Independence It is capacity to change the internal schema
without
having to change conceptual schema. Hence, the external schemas need not be
changed
as well. Changes to the internal schema may be needed because some physical
files had
to be reorganized to improve the performance of retrieval or update. If the same
data as
before remains in the database, the conceptual schema needs not be changed.
_ Logical Data Independence - It is the capacity to change the conceptual
schema
without having to change external schemas or application programs. The
conceptual
schema may be changed to expand the database (by adding a record type or
data item),
to change constraints, or to reduce the database (by removing a record type or
data
item). Only the view definition and the mappings need be changed in a DBMS
that
supports logical data independence. Changes to constraints can be applied to
the
conceptual schema without affecting the external schemas or application
programs.
Q.22 Write short notes on:
(i) Weak and strong entity sets.
(ii) Types of attributes.
(iii) Oracle Instance.
(iv) Mid square method of hashing. (4 x 4 = 16 )
Ans: (i) Weak and Strong entity sets: A strong entity set has a primary key.
All
tuples in the set are distinguishable by that key. A weak entity set has no primary
key
unless attributes of the strong entity set on which it depends are included. Tuples
in a
weak entity set are partitioned according to their relationship with tuples in a
strong entity
set. Tuples within each partition are distinguishable by a discriminator, which is a
set of
attributes. A strong entity set has a primary key. All tuples in the set are
distinguishable
by that key. A weak entity set has no primary key unless attributes of the strong
entity set
on which it depends are included. Tuples in a weak entity set are partitioned
according to
their relationship with tuples in a strong entity set. Tuples within each partition
are
distinguishable by a discriminator, which is a set of attributes.
(ii) Types of attributes:An attribute's type determines the kind of values that
are allowed
in the attribute. For example, the value version 1 is not valid for an attribute
defined as an
integer, but the value 1 is valid. Numeric types (such as integer or real) can also
be
limited to a predefined range by their attribute definition.
Choice :An attribute with a list of predefined values.
ID Reference: An attribute with a value that is a Unique ID value from another
element.
It is typically used for element-based cross-references.
ID References: An attribute with a value of one or more Unique ID values from
another element.
Integer: An attribute with a whole number value (no decimal parts). Examples
of valid
integers are 22, -22, and +322. An integer can be defined to fall within a range.
Integers: An attribute with a value of one or more integers. Enter each number
on a
separate line in the Attribute Value text box.
Real An attribute with a real number value, with or without a decimal part (the
value
can also be expressed in scientific notation). Examples of valid real numbers are
2, 22.4, 0.22, and 2.3e-1. A real number can be defined to fall within a range.
Reals: An attribute with a value of one or more real numbers. Enter each
number on a
separate line in the Attribute Value text box.
String: An attribute with a value of a series of characters (text).
Strings: An attribute with a value of one or more strings. Enter each string on a
separate line in the Attribute Value text box.
Unique ID: An attribute with a value of a unique text string. An element can
have only
one ID attribute (which can be of type Unique ID or Unique IDs). All ID values
must be
unique in the document or book. An element with a Unique ID attribute can be
the source
for an element-based cross-reference.
Unique IDs: An attribute with a value of one or more unique text strings. Enter
each
string on a separate line in the Attribute Value text box.
(iii) Oracle Instances: An instance is the (executed) Oracle software and the
memory
they use. It is the instance that manipulates the data stored in the database. It
can be
started independent of any database. It consists of:
1) A shared memory area that provides the communication between various
processes.
2) Upto five background processes which handled various tasks.
Whenever an oracle instance starts, the file INIT.ORA is executed.
(iv) Mid square method of hashing: In midsquare hashing, the key is squared
and the
address selected from the middle of the squared number.
Mid square method
* Square K.
* Strip predetermined digits from front and rear.
* e.g., use thousands and ten thousands places.
FROM WORKS
WHERE COMPANYNAME = First Bank Corporation;
(ii) SELECT EMPLOYEE_NAME, COMPANYNAME
FROM WORKS
ORDER BY COMPANYNAME, EMPLOYEE_NAME DESC;
(iii) UPDATE COMPANY
SET CITY = New Delhi
WHERE COMPANY_NAME = First Bank Corporation;
Q.25 Discuss the correspondence between the E-R model construct and the
relation model construct.
Show how each E-R model construct can be mapped to the relational model
using the
suitable example?
Ans: An entity-relationship model (ERM): An entity-relationship model (ERM)
is
an abstract conceptual representation of structured data. Entity-relationship
modeling is a
relational schema database modeling method, used in software engineering to
produce a
type of conceptual data model (or semantic data model) of a system, often a
relational
database, and its requirements in a top-down fashion. Diagrams created using
this process
are called entity-relationship diagrams, or ER diagrams or ERDs for short.
ER-to-Relational Mapping Algorithm:
1) Step 1: Mapping of regular entity types: For each strong entity type E,
create a
relation T that includes all the simple attributes of a composite attribute.
2) Step2: Mapping of weak entity types: For each weak entity type W with
owner entity
type E, create relation R and include all simple attributes (or simple components
of