0% found this document useful (0 votes)
4K views35 pages

Bca II Sem Dbms Question Bank With Answers

Exam related content

Uploaded by

adhura.khwab417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4K views35 pages

Bca II Sem Dbms Question Bank With Answers

Exam related content

Uploaded by

adhura.khwab417
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 35

BCA II SEM

DATABASE MANAGEMENT SYSTEM


QUESTION BANK
Short type questions:

1. Define database management system?


Database management system (DBMS) is a collection of interrelated data and a set of programs to
access those data.
2. Who is a DBA? What are the responsibilities of a DBA?
A database administrator (short form DBA) is a person responsible for the design, implementation,
maintenance and repair of an organization’s database. They are also known by the titles Database
Coordinator or Database Programmer. The role includes the development and design of database
strategies, monitoring and improving database performance and capacity, and planning for future
expansion requirements. They may also plan, co-ordinate and implement security measures to
safeguard the database.
3. What is a data model? List the types of data model used?
A database model is the theoretical foundation of a database and fundamentally determines in which
manner data can be stored, organized, and manipulated in a database system. It thereby defines the
infrastructure offered by a particular database system. The most popular example of a database model
is the relational model.
Types of data model used:
 Hierarchical model
 Network model
 Relational model
 Entity-relationship
 Object-relational model
 Object model
4. List any eight applications of DBMS.
a) Banking b) Airlines c) Universities d) Credit card transactions e) Tele
communication f) Finance g) Sales h) Manufacturing i) Human resource
5. What are the disadvantages of file processing system?
The disadvantages of file processing systems are
a) Data redundancy and inconsistency b) Difficulty in accessing data
c) Data isolation d) Integrity problems e) Atomicity problems
f) Concurrent access anomalies
6. What are the advantages of using a DBMS?
The advantages of using a DBMS are
a) Controlling redundancy b) Restricting unauthorized access
c) Providing multiple user interfaces d) Enforcing integrity constraints
e) Providing backup and recovery
7. Give the levels of data abstraction?
a) Physical level b) Logical level c) View level
8. Define instance and schema?
Instance: Collection of data stored in the data base at a particular moment is called an Instance of the
database.
Schema: The overall design of the data base is called the data base schema.
9. Define the following terms:
1) Physical schema
2) logical schema.
Physical schema: The physical schema describes the database design at the physical level, which is
the lowest level of abstraction describing how the data are actually stored.
Logical schema: The logical schema describes the database design at the logical level, which
describes what data are stored in the database and what relationship exists among the data.
10. What is conceptual schema?
The schemas at the view level are called subschema’s that describe different views of the database.
11. Define data model?
A data model is a collection of conceptual tools for describing data, data relationships, data
semantics and consistency constraints.
12. What is storage manager?
A storage manager is a program module that provides the interface between the low level data stored
in a database and the application programs and queries submitted to the system.
13. What is the purpose of storage manager?
The storage manager is responsible for the following a) Interaction with the file manager b)
Translation of DML commands in to low level file system commands c) Storing, retrieving and
updating data in the database
14. What is a data dictionary?
A data dictionary is a data structure which stores meta data about the structure of the database i.e. the
schema of the database.
15. What is an entity relationship model?
The entity relationship model is a collection of basic objects called entities and relationship among
those objects. An entity is a thing or object in the real world that is distinguishable from other
objects.
16. What are attributes? Give examples.
An entity is represented by a set of attributes. Attributes are descriptive properties possessed by each
member of an entity set. Example: possible attributes of customer entity are customer name,
customer id, Customer Street, customer city.
17. What is relationship? Give examples
A relationship is an association among several entities.
Example: A depositor relationship associates a customer with each account that he/she has.
18. Define the following terms i) Entity set ii) Relationship set
Entity set: The set of all entities of the same type is termed as an entity set.
Relationship set: The set of all relationships of the same type is termed as a relationship set.
19. Define single valued and multivalued attributes.
Single valued attributes: attributes with a single value for a particular entity are called single valued
attributes.
Multivalued attributes: Attributes with a set of value for a particular entity are called multivalued
attributes.
20. What are stored and derived attributes?
Stored attributes: The attributes stored in a data base are called stored attributes.
Derived attributes: The attributes that are derived from the stored attributes are called derived
attributes.
21. What are composite attributes?
Composite attributes can be divided in to sub parts.
22. Define the terms i) Entity type ii) Entity set
Entity type: An entity type defines a collection of entities that have the same attributes.
Entity set: The set of all entities of the same type is termed as an entity set.
23. What is meant by the degree of relationship set?
The degree of relationship type is the number of participating entity types.
24. Define the terms i) Key attribute ii) Value set
Key attribute: An entity type usually has an attribute whose values are distinct from each individual
entity in the collection. Such an attribute is called a key attribute.
Value set: Each simple attribute of an entity type is associated with a value set that specifies the set
of values that may be assigned to that attribute for each individual entity.
25. Define weak and strong entity sets?
Weak entity set: entity set that do not have key attribute of their own are called weak entity sets.
Strong entity set: Entity set that has a primary key is termed a strong entity set.
26. What does the cardinality ratio specify?
Mapping cardinalities or cardinality ratios express the number of entities to which another entity can
be associated. Mapping cardinalities must be one of the following:
 One to one
 One to many
 Many to one
 Many to many
27. Explain the two types of participation constraint.
Total: The participation of an entity set E in a relationship set R is said to be total if every entity in E
participates in at least one relationship in R.
Partial: if only some entities in E participate in relationships in R, the participation of entity set E in
relationship R is said to be partial.
28. What is meant by lossless-join decomposition?
Any given decomposition is said to be lossless when the reconstruction of the relation R is easy from
the decomposed tables with the help of joins. It is the preferred choice since the data/info will not be
lost from the given relation after its decomposition. Here, the join results in the very same, original
relation in the beginning.
29. List the disadvantages of relational database system.
Repetition of data Inability to represent certain information.
30. What is first normal form?
The domain of attribute must include only atomic (simple, indivisible) values.
31. What is meant by functional dependencies?
The functional dependency is a relationship that exists between two attributes. It typically exists
between the primary key and non-key attribute within a table.
Consider a relation schema R and a C R and ß C R. The functional dependency a ß holds on
relational schema R if in any legal relation r(R), for all pairs of tuples t1 and t2 in r such that t1 [a]
=t1 [a], and also t1 [ß] =t2 [ß].
32. What are the uses of functional dependencies?
To test relations to see whether they are legal under a given set of functional dependencies.
To specify constraints on the set of legal relations.
33. What is meant by computing the closure of a set of functional dependency?
The closure of F denoted b y F is the set of functional dependencies logically implied by F.
34. What is meant by normalization of data?
It is a process of analyzing the given relation schemas based on their Functional Dependencies (FDs)
and primary key to achieve the properties
 Minimizing redundancy
 Minimizing insertion, deletion and updating anomalies
35. Define the following terms i) DDL ii) DML
DDL: Data base schema is specified by a set of definitions expressed by a special language called a
data definition language.
DML: A data manipulation language is a language that enables users to access or manipulate data as
organized by the appropriate data model
36. Write short notes on relational model.
The relational model uses a collection of tables to represent both data and the relationships among
those data. The relational model is an example of a record based model.
37. Define tuple and attribute.
Attributes: column headers are called attributes
Tuple: A single row is called tuple
38. Define the term relation.
Relation is a subset of a Cartesian product of list domains.
39. Define tuple variable.
Tuple variable is a variable whose domain is the set of all tuples.
40. Define the term Domain.
For each attribute there is a set of permitted values called the domain of that attribute.
41. What is a candidate key?
Minimal super keys are called candidate keys.
42. What is a primary key?
The attribute which is uniquely identified the relation is used as Primary key.
43. What is a super key?
A super key is a set of one or more attributes that collectively allows us to identify uniquely an entity
in the entity set.
44. List the table modification commands in SQL?
 Deletion
 Insertion
 Update
45. What are the ACID properties?
ACID properties are (i) atomicity, (ii) consistency, (iii) isolation and (iv) durability. It is a set of
properties that guarantee database transactions are processed reliably. In the context of databases, a
single logical operation on the data is called a transaction. For example, a transfer of funds from one
bank account to another, even though that might involve multiple changes (such as debiting one
account and crediting another), is a single transaction.
46. What are two pitfalls (problem) of lock-based protocols?
 Deadlock
 Starvation
47. What is transaction?
Collections of operations that form a single logical unit of work are called transactions.
48. What are the properties of transaction?
The properties of transactions are:
 Atomicity
 Consistency
 Isolation
 Durability
49. What is recovery management component?
Ensuring durability is the responsibility of a software component of the base system called the
recovery management component.
50. When is a transaction rolled back?
Any changes that the aborted transaction made to the database must be undone. Once the changes
caused by an aborted transaction have been undone, then the transaction has been rolled back.
51. What are the states of transaction?
The states of transaction are
 Active
 Partially committed
 Failed
 Aborted
 Committed
 Terminated
52. What is a shadow copy scheme?
It is simple, but efficient, scheme called the shadow copy schemes. It is based on making copies of
the database called shadow copies that one transaction is active at a time. The scheme also assumes
that the database is simply a file on disk.
53. Give the reasons for allowing concurrency?
The reasons for allowing concurrency is if the transactions run serially, a short transaction may have
to wait for a preceding long transaction to complete, which can lead to unpredictable delays in
running a transaction. So concurrent execution reduces the unpredictable delays in running
transactions.
54. What are the two types of serializability?
The two types of serializability is:
 Conflict serializability
 View serializability
55. Define lock?
Lock is the most common used to implement the requirement is to allow a transaction to access a
data item only if it is currently holding a lock on that item.
56. What are the different modes of lock?
The modes of lock are:
 Shared
 Exclusive
57. Define deadlock?
Neither of the transaction can ever proceed with its normal execution. This situation is called
deadlock.
58. Define the phases of two phase locking protocol.
There are two phases:
 Growing phase: a transaction may obtain locks but not release any lock.
 Shrinking phase: a transaction may release locks but may not obtain any new locks.
59. What are the two methods for dealing deadlock problem?
The two methods for dealing deadlock problem is deadlock detection and deadlock recovery.
60. What is a recovery scheme?
An integral part of a database system is a recovery scheme that can restore the database to the
consistent state that existed before the failure.
61. What are the two types of errors?
The two types of errors are:
 Logical error
 System error
62. What is meant by log-based recovery?
The most widely used structures for recording database modifications is the log. The log is a
sequence of log records, recording all the update activities in the database. There are several types of
log records.
63. Define shadow paging.
An alternative to log-based crash recovery technique is shadow paging. This technique needs fewer
disk accesses than do the log-based methods.
64. Define page.
The database is partitioned into some number of fixed-length blocks, which are referred to as pages.
65. Explain current page table and shadow page table.
The key idea behind the shadow paging technique is to maintain two page tables during the life of
the transaction: the current page table and the shadow page table. Both the page tables are identical
when the transaction starts. The current page table may be changed when a transaction performs a
write operation.
66. What are the drawbacks of shadow-paging technique?
 Commit Overhead
 Data fragmentation
 Garbage collection
67. Differentiate strict two phase locking protocol and rigorous two phase locking protocol.
In strict two phase locking protocol all exclusive mode locks taken by a transaction is held until that
transaction commits. Rigorous two phase locking protocol requires that all locks be held until the
transaction commits.
68. How the time stamps are implemented?
Use the value of the system clock as the time stamp. That is a transaction’s time stamp is equal to the
value of the clock when the transaction enters the system.
Use a logical counter that is incremented after a new timestamp has been assigned; that is the time
stamp is equal to the value of the counter.
69. What are the time stamps associated with each data item?
W-timestamp (Q) denotes the largest time stamp if any transaction that executed WRITE (Q)
successfully.
R-timestamp (Q) denotes the largest time stamp if any transaction that executed READ (Q)
successfully.
70. What are the actions performed by DBA?
 Account creation
 Privilege granting
 Privilege revocation
 Security level assignment

Long Questions:

1. Explain about Database Architecture.

The term "database architecture" refers to the structural design and methodology of a database system,
which forms the core of a Database Management System (DBMS). This architecture dictates how data is
stored, organized, and retrieved, playing a crucial role in the efficiency and effectiveness of data
management.

Database architecture describes how a database management system (DBMS) will be integrated with
your application. When designing a database architecture, you will make decisions that will change how
your applications are created.

The architecture of a database is not a one-size-fits-all solution. It varies significantly based on the needs
of the organization, the type of data being managed, and the specific applications that interact with the
database. From simple structures that manage daily transactions in a small business to complex
architectures that handle massive amounts of data in large enterprises, the spectrum of database
architecture is broad and diverse.

At its core, a database system is an intricate set of software tools and mechanisms that store, manage,
and retrieve data. A DBMS acts as an intermediary between the user and the database, ensuring that the
data is easily accessible, consistently organized, and securely maintained. The effectiveness of a DBMS
hinges on its underlying architecture, which must be robust, scalable, and capable of handling various
data-related tasks with efficiency.

The primary functions of a DBMS include data storage, retrieval, updating, and management of database
security. It should provide a convenient and efficient way to define, create, manage, and control access
to the database. A well-designed DBMS architecture ensures that these functions are performed
seamlessly, providing a stable and reliable platform for data management.
One of the fundamental aspects of database architecture is its tier architecture. This concept refers to the
physical and logical separation of functionalities into different layers or tiers, such as data storage and
data processing.

For instance, in a three-tier architecture, the first tier might be dedicated to raw data storage, the second
tier to processing and managing data, and the third to presenting the data to users through a GUI or API.

The most common models include:

One-tier architecture
In one-tier architecture, the database, user interface, and application logic all reside on the same machine
or server. It's typically used for small-scale applications where simplicity and cost-effectiveness are
priorities. Because there are no network delays involved, this type of tier architecture is generally a fast
way to access data.

On a single-tier application, the application and database reside on the same device.

An example of a one-tier architecture would be a mobile application that uses Realm, the open-source
mobile database by MongoDB, as a local database. In that case, both the application and the database are
running on the user’s mobile device.

Two-tier architecture
Two-tier architecture consists of multiple clients connecting directly to the database. This tier
architecture is also known as client-server architecture.
In a two-tier architecture, clients are connecting directly to a database.

This tier architecture used to be more common when a desktop application would connect to a single
database hosted on an on-premise database server — for example, an in-house customer relationship
management (CRM) that connects to an Access database.

Three-tier architecture
Most modern web applications use a three-tier architecture. In this architecture, the clients connect to a
back end, which in turn connects to the database. Using this approach has many benefits:
 Security: Keeping the database connection open to a single back end reduces the risks of being
hacked.
 Scalability: Because each layer operates independently, it is easier to scale parts of the
application.

 Faster deployment: Having multiple tiers makes it easier to have a separation of concerns and to
follow cloud-native best practices, including better continuous delivery processes.
In a three-tier architecture, the information between the database and the clients is relayed by a back-
end server.

An example of this type of architecture would be a React application that connects to a Node.js back
end. The Node.js back end processes the requests and fetches the necessary information from a database
such as MongoDB Atlas, using the native driver. This architecture is described in greater detail in the
next section.

Q.2 Define trigger and explain its three parts?


A trigger is a special kind of stored procedure that is activated ("triggered") in response to a particular
event in a database.

trigger is called automatically when a data modification event occurs against a table.

There are different kinds of events that can activate a trigger like inserting or deleting rows in a table, a
user logging into a database server instance, an update to a table column, a table is created, altered, or
dropped, etc.

Types of Triggers
1) DML triggers are automatically fired when an INSERT, UPDATE or DELETE event occurs on a
table.
2) DDL triggers are automatically invoked when a CREATE, ALTER, or DROP event occurs in a
database.
3) Logon triggers is invoked when a LOGON event is raised when a user session is established.

Q.3 Explain about Selection, Projection, Rename, division and Cartesian product operations
in relational algebra?
RELATIONAL ALGEBRA is a widely used procedural query language. It collects instances of
relations as input and gives occurrences of relations as output. It uses various operations to perform this
action. SQL Relational algebra query operations are performed recursively on a relation. The output of
these operations is a new relation, which might be formed from one or more input relations.
SELECT (σ)
The SELECT operation is used for selecting a subset of the tuples according to a given selection
condition. Sigma(σ)Symbol denotes it. It is used as an expression to choose tuples which meet the
selection condition. Select operator selects tuples that satisfy a given predicate.

σp(r)
σ is the predicate
r stands for relation which is the name of the table
p is prepositional logic

Example 1
σ topic = "Database" (Tutorials)
Output – Selects tuples from Tutorials where topic = ‘Database’.

Example 2
σ topic = "Database" and author = "guru99"( Tutorials)
Output – Selects tuples from Tutorials where the topic is ‘Database’ and ‘author’ is guru99.

Example 3
σ sales > 50000 (Customers)
Output – Selects tuples from Customers where sales is greater than 50000

Projection(π)
The projection eliminates all attributes of the input relation but those mentioned in the projection list.
The projection method defines a relation that contains a vertical subset of Relation.

This helps to extract the values of specified attributes to eliminates duplicate values. (pi) symbol is used
to choose attributes from a relation. This operator helps you to keep specific columns from a relation
and discards the other columns.

Example of Projection:
Consider the following table

CustomerID CustomerName Status


1 Google Active
2 Amazon Active
3 Apple Inactive
4 Alibaba Active

Here, the projection of CustomerName and status will give


Π CustomerName, Status (Customers)
CustomerName Status (Customers)
Google Active
Amazon Active
Apple Inactive
Alibaba Active
Rename (ρ)
Rename is a unary operation used for renaming attributes of a relation.
ρ (a/b) R will rename the attribute ‘b’ of relation by ‘a’.

Union operation (υ)


UNION is symbolized by ∪ symbol. It includes all tuples that are in tables A or in B. It also eliminates
duplicate tuples. So, set A UNION set B would be expressed as:

The result <- A ∪ B


For a union operation to be valid, the following conditions must hold –
R and S must be the same number of attributes.
Attribute domains need to be compatible.
Duplicate tuples should be automatically removed.

Example
Symbol denotes it. The result of A – B, is a relation which includes all tuples that are in A but not in B.
The attribute name of A has to match with the attribute name in B.
The two-operand relations A and B should be either compatible or Union compatible.
It should be defined relation consisting of the tuples that are in relation A, but not in B.

Intersection
An intersection is defined by the symbol ∩
A∩B
Defines a relation consisting of a set of all tuple that are in both A and B. However, A and B must be
union-compatible.

Cartesian Product(X) in DBMS


Cartesian Product in DBMS is an operation used to merge columns from two relations. Generally, a
cartesian product is never a meaningful operation when it performs alone. However, it becomes
meaningful when it is followed by other operations. It is also called Cross Product or Cross Join.

Example – Cartesian product σ column 2 = ‘1’ (A X B)


Output – The above example shows all rows from relation A and B whose column 2 has value 1

σ column 2 = ‘1’ (A X B)
column 1 column 2
1 1
1 1

Join Operations
Join operation is essentially a cartesian product followed by a selection criterion.
Join operation denoted by ⋈.
JOIN operation also allows joining variously related tuples from different relations.

Types of JOIN:
Various forms of join operation are:

Inner Joins:
1) Theta join
2) EQUI join
3) Natural join
Outer join:
1) Left Outer Join
2) Right Outer Join
3) Full Outer Join

 Inner Join
In an inner join, only those tuples that satisfy the matching criteria are included, while the rest are
excluded. Let’s study various types of Inner Joins:

1) Theta Join: The general case of JOIN operation is called a Theta join. It is denoted by symbol θ
Example
A ⋈θ B
Theta join can use any conditions in the selection criteria.

For example:
A ⋈ A.column 2 > B.column 2 (B)
A ⋈ A.column 2 > B.column 2 (B)
column 1 column 2
1 2

2) EQUI join
When a theta join uses only equivalence condition, it becomes a equi join.
For example:

A ⋈ A.column 2 = B.column 2 (B)


A ⋈ A.column 2 = B.column 2 (B)

column 1 column 2
1 1

EQUI join is the most difficult operations to implement efficiently using SQL in an RDBMS and one
reason why RDBMS have essential performance problems.

3) Natural join (⋈)


Natural join can only be performed if there is a common attribute (column) between the relations. The
name and type of the attribute must be same.

Example
Consider the following two tables
1. C
Num Square
2 4
3 9

2. D
Num Cube
2 8
3 27

3. C ⋈ D
C⋈D
Num Square Cube
2 4 8
3 9 27

 Outer join
In an outer join, along with tuples that satisfy the matching criteria, we also include some or all tuples
that do not match the criteria.

1) Left Outer Join(A ⟕ B)


In the left outer join, operation allows keeping all tuple in the left relation. However, if there is no
matching tuple is found in right relation, then the attributes of right relation in the join result are filled
with null values.

Consider the following 2 Tables


1. A
Num Square
2 4
3 9
4 16

2. B
Num Cube
2 8
3 18
5 75

3. A Left Outer Join B


A⋈B
Num Square Cube
2 4 8
3 9 18
4 16 –

2) Right Outer Join ( A ⟖ B )


In the right outer join, operation allows keeping all tuple in the right relation. However, if there is no
matching tuple is found in the left relation, then the attributes of the left relation in the join result are
filled with null values.

A Right Outer Join B (A ⋈ B)


Num Cube Square
2 8 4
3 18 9
5 75 –

3) Full Outer Join ( A ⟗ B)


In a full outer join, all tuples from both relations are included in the result, irrespective of the matching
condition.
A Full Outer Join B (A ⋈ B)
Num Cube Square
2 4 8
3 9 18
4 16 –
5 – 75

Summary
Operation(Symbols) Purpose
Select(σ) The SELECT operation is used for selecting a subset of the tuples
according to a given selection condition
Projection(π) The projection eliminates all attributes of the input relation but those
mentioned in the projection list.
Union Operation(∪) UNION is symbolized by symbol. It includes all tuples that are in
tables A or in B.
Set Difference(-) – Symbol denotes it. The result of A – B, is a relation which includes
all tuples that are in A but not in B.
Intersection(∩) Intersection defines a relation consisting of a set of all tuple that are in
both A and B.
Cartesian Product(X) Cartesian operation is helpful to merge columns from two relations.
Inner Join Inner join, includes only those tuples that satisfy the matching criteria.
Theta Join(θ) The general case of JOIN operation is called a Theta join. It is denoted
by symbol θ.
EQUI Join When a theta join uses only equivalence condition, it becomes a equi
join.
Natural Join(⋈) Natural join can only be performed if there is a common attribute
(column) between the relations.
Outer Join In an outer join, along with tuples that satisfy the matching criteria.
Left Outer Join(Left Outer In the left outer join, operation allows keeping all tuple in the left
Join) relation.
Right Outer join(Right In the right outer join, operation allows keeping all tuple in the right
Outer join) relation.
Full Outer Join(Full Outer In a full outer join, all tuples from both relations are included in the
Join) result irrespective of the matching condition.

Q.4 Explain advantages of DBMS.


a) Minimal Data Redundancy: Due to centralized database, it is possible to avoid
unnecessary duplication of information. Ex. All information about bank customer can be
kept centralized.
b) Improved Data Inconsistency: Data inconsistency occurs due to data redundancy. Due to
centralized database it is possible to avoid unnecessary duplication of information.
c) Efficient Data Access: DBMS provides a variety of techniques to retrieve data.
d) Improved Data Sharing: In DBMS Data is maintained centrally, all authorized users and
application programs can share this data easily.
e) Improved Data Integrity: Data integrity means that data contained in the database is both
correct and consistent. DBMS software provides different way to implement such types of
rules.
f) Guaranteed Atomicity: Any operation on database must be atomic. It is responsibility of
the DBMS software ensure such kind of atomicity.
g) Improved Concurrent Access: Multiple users are allowed to access data simultaneously
(concurrently). As Database is maintained centrally, data can be shared easily among
multiple users.
h) Improved Security: DBMS software provides way to control the access to data for
different user according to their requirements.

Q.4 Function and responsibility of DBA.


1. Defining conceptual schema and database creation (Schema Definition): The DBA Defines
the overall logical structure of database. According to this schema database will be developed to
stored required data for system.

2. Storage structure and access method definition: DBA decides how the data is to be
represented in the stored database process is called physical database design.

3. Assisting Application Programmers: The DBA provides assistance to application programmers


to develop application programs.

4. Granting authorization to users (Approving Data Access): The DBA determines which user
access to which part of the database. This is required to prevent unauthorized access of a
database.

5. Physical organization modification: The DBA modifies the physical organization of the
database to improve performance.

6. Monitoring performance: The DBA monitors performance of the system and making changes
in physical or logical schema if required.

7. Backup and Recovery: Database is a valuable asset for any organization. It should not be lost or
damaged. The DBA ensures this by taking proper backup of Database.

Q.4 Component of Data dictionary.


1. Entities: It is real physical object or event. The user is interested in keeping track of.
OR
Any item about which information is stored is called entity.
Example: Employee of company

2. Attributes: An attribute is a property or characteristic (field) of an entity.


Example: Employee‘s EMP_NO, EMP_SALARY etc.

3. Entity set: A collection of entities of same type are called entity set.
Example: Employee of all companies.

4. Relationships: The association or the ways that different entities relate to each other is called
relationships.
Relationship could be of following type:
 One to One (1:1) Relationship
Example: One employee having one employee number.

EMPLOYEE EMP_NO

 One to Many(1:m) Relationship


Example: One Department having more than one employee OR One salary is given to many
employees.
DEPARTMENT EMPLOYEE

 Many to Many (n:m) Relationship


Example: Much salary is given to many employees.

EMPLOYEE SALARY

5. Key: The data item for which a computer uses to identify a record in a database system is
referred to as key. There are several keys available in a table. Two main keys are Primary key
and foreign key.

Q. 5 What is Data Model? Explain all Data Model.


A data model is a collection of conceptual tools for describing Data, Data Relationships, Data
schema and Consistency constraints.
Record Based Data Models
The most widely used Record Based Data Models are
 Hierarchical Data Model
 Network Data Model
 Relational Data Model.

1. Hierarchical Data Model


 In Hierarchical data model tree concept is used to represent data and relationship
among this data.
 The nodes of tree are connected with pointer or link.
 In tree structure each child records can have only one parent record, and each parent
record have zero or more than one child so one-to-one or one-to-many relationship is
possible.
 The records are represented by rectangular box and relationship between these records is
represented by arcs (pointer).
 This type of structure is also known as tree structure diagram.

2. Network Data Model


 This is an extension of the Hierarchical model.
 In this model data is organized more like a graph, and are allowed to have more
than one parent node.
 Network Database Model is same like Hierarchical Model, but the only difference is
that it allows a record to have more than one parent.
 It replaces the hierarchical tree with a graph.
 It represents the data as record types and many-to-many relationship.
 This model is easy to design and understand.
 This was the most widely used database model, before Relational Model was introduced.

3. Relational Data Model.


 It represents data as relations or tables.
 Relational database simplifies the database structure by making use of tables and
columns.
 Relational data model describe a database as a collection of tables to represent data and
relationship among those data.
 Each table is called relation.
 Each relation has number of columns that is attributes of table.
 Each relation has number of unlimited rows called tuples.

Q6. Explain all Views.


1. Internal (Physical) Level:

 It is the lowest level of data abstraction.


 It is the physical representation of the database on the computer and this view is found at
the lowest level of abstraction of database.
 It is also known as physical level.

2. Conceptual (Logical) Level:


 It is middle level or next level in the 3-tier architecture.
 It contains the logical structure of entire database as seen by DBA.
 It describes what data are stored in the database and what relationship exists among
those data.
 It is also known as logical level.

3. External (View) Level:


 It is user’s view of database.
 This is the highest level of data abstraction.
 It is known as a view level.
 Each user has a view of the “real world” represented in a form that is familiar for that user
the eternal view Example: Customer information for transaction.

Q7. Explain Group by having and order by with Example.


The SQL GROUP BY Clause is used along with the group functions to retrieve data
grouped according to one or more columns.
Syntax:
Select column1, column2……. columnN, Aggregate Function (argument) From TableName
Group By column1, column2……. columnN;
Example:
Id Name Dept Age Salary Location

100 Ramesh Electrical 24 25000 Bangalore

101 Hrithik Electronics 28 35000 Bangalore

102 Harsha Aeronautics 28 35000 Mysore

103 Soumya Electronics 22 20000 Bangalore

104 Priya InfoTech 25 30000 Mangalore

SELECT dept, SUM (salary) FROM employee GROUP BY dept; The


output would be like:

Dept Salary

Electrical 25000

Electronics 55000

Aeronautics 35000

InfoTech 30000

SQL ORDER BY
 The ORDER BY keyword is used to sort the result-set in ascending or descending
order.
 The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.
Syntax:
SELECT column1, column2…..FROM table_name
ORDER BY column1, column2 ... ASC|DESC;

Id Name Dept Age Salary Location

100 Ramesh Electrical 24 25000 Bangalore

101 Hrithik Electronics 28 35000 Pune

103 Soumya Electronics 22 20000 Bombay

104 Priya InfoTech 25 30000 Mangalore

Example:

SELECT name, salary FROM employee ORDER BY


salary; The output would be like
Name Salary

Soumya 20000

Ramesh 25000

Priya 30000

Hrithik 35000

 By default, the ORDER BY Clause sorts data in ascending order.


 If you want to sort the data in descending order, you must explicitly specify it as
shown below.
SELECT name, salary FROM employee ORDER BY name, salary DESC;

SQL HAVING Clause


 Having clause is used to filter data based on the group functions.
 This is similar to WHERE condition but is used with group functions.
 Group functions cannot be used in WHERE Clause but can be used in HAVING
clause.
 The HAVING clause must follow the GROUP BY clause in a query and must
also precedes the ORDER BY clause if used.
Syntax:
SELECT column1, column2 FROM TableName WHERE [conditions] GROUP BY
column1, column2 HAVING [conditions];

Id Name Dept Age Salary Location

100 Ramesh Electrical 24 25000 Bangalore

101 Hrithik Electronics 28 35000 Pune

103 Soumya Electronics 22 20000 Bombay

104 Priya InfoTech 25 30000 Mangalore

SELECT dept, SUM (salary) FROM employee GROUP BY dept HAVING SUM (salary)
> 25000;

Dept salary

Electronics 55000

Aeronautics 35000

InfoTech 30000
Q8. Explain DDL and DML commands with Example.
1. DDL (Data-Definition Language)
It is set of SQL commands used to create, modify and delete database objects like table.
Provides commands:
 CREATE
 ALTER
 TRUNCATE
 DROP
 RENAME

a) CREATE
Create command used to create a table in database.
Syntax:
CREATE TABLE TableName (ColumnName1 datatype (size), … ColumnNameN datatype (size));

Example:
Create table customer (cno varchar2 (6), name varchar2 (20), city varchar2 (15));

b) ALTER
Used to modify structures of a table.
Used to either add, modify, or drop columns in a table
Syntax:
Adding New Columns
Alter table TableName Add (NewColumnName Datatype (size), NewColumnName
Datatype (size)….);

Modifying Existing Columns


Alter table TableName Modify (ColumnName NewDatatype (NewSize));

Dropping (deleting) Existing Columns


Alter table TableName Drop column ColumnName;

Example:
1. Alter table student ADD (Gender varchar2 (10));
2. Alter table student modify (sname varchar2 (15));
3. alter table student drop column dept;

c) TRUNCATE TABLE
Truncate table used to delete all data from a table
Logically, this is same to DELETE statement that deletes all rows
Truncate command is faster than DELETE command
The number of deleted rows are not returned
Syntax:
TRUNCATE TABLE
TableName;
Example:

TRUNCATE TABLE client_master;

d) DROP TABLE
DROP command is used to delete or destroy table from a database
Syntax:
DROP TABLE TableName;

Example:
DROP TABLE client_master;

e) RENAME TABLE
RENAME command is used to rename the existing table Name.
Syntax:
Rename TableName to NewTableName;
Example:
Rename Student to StudentMaster;

2. DML Commands - (Data-Manipulation language)


DML commands are generally used for manipulating data stored in tables.
So DML commands are work on data stored in tables rather than table definition.
It includes following commands
 INSERT
 UPDATE
 DELETE

a) INSERT
Used to insert data into a table or create a new row in table.
Syntax:
Insert into TableName (columnname1, columnname2) values value1, value2);
Example:
Insert into client_master (clientno, name) values (‘C01’,’Preeti’);

b) UPDATE
The UPDATE command is used to change or modify data of a table
Update command used to update Selected rows from table or All the rows from table
Syntax:
Update TableName Set columnname1 = value1, Columnname2= value2 where Condition;

Example:
Update client_master Set city=’Bombay’ where clientno=’C01’;
c) DELETE
Delete command used to delete data or rows from a table. Delete command used to delete
Selected rows from table or All the rows from table
Syntax:
Delete from TableName Where Condition;

Example:
Delete from client_master Where client_no=’C01’;

Q.9 Draw and Explain E-R model Symbol.


Ans:

Q.8 Explain Generalization and Specialization with example.


Specialization
"Specialization is the process of defining sub-classes of a super-class. Specialization identifies the
sub-sets of an entity set. Specialization is a top-down process to define super class/sub-class
relationships.
Example:
Consider the Employee entity set having attributes eid, name, address, bdate, contact_no,
salary, work_hrs, rate_per_hr, etc.
Employees can be either of two types
Permanent employees having fixed salary
Part-time employees having variable salary, based on number of hours worked and rate per
hour.

Generalization
"Generalization is the process of defining a super-class from sub-classes based on some
common characteristics."
Generalization identifies a super-class from different entity sets.
Some attributes are common to given entity sets.
Generalization is a bottom-up process to define super-class/sub-class relationships.
Example: consider the two entity sets Car and Truck
They have many attributes in common.
Example: vehicle_id, licence_plat_no, company, model, and price are common attributes to
both of these entity sets
Vehicle can be defined as a super-class for two sub-classes Car and Truck.

Q.9 Give the Difference between primary key and unique key.
Ans:
Primary Key Unique Key

A Column defines as primary key does A Column defines as unique key cannot have
not contain duplicate value as well as duplicate value but it have null value.
null value.
Syntax: Syntax:
ColumnName Datatype (Size) Primary ColumnName Datatype (Size) Unique Key.
Key.
Example: Create table Account(Ano Example: Create table Account(Ano
number(3) Primary Key, Balance number(3) Unique Key, Balance number(8),
number(8), Branch varchar2(20)); Branch varchar2(20));
Primary Key does not allow null value in Unique Key allows null value as well as
column. duplicate null value in a column.
A table cannot have more than one A Table can have more than one column
primary key. define as unique key.

Q.10 Explain foreign key with example.


Ans:
A foreign key constrain is also called referential integrity constrain which is define between two table.
A Foreign key is a set of one or more column whose value is derive from the primary key or
unique key of other table.
A Table in which Foreign key is defined is called Primary Table or Master Table or Parent
Table.
Syntax:
ColumnName Datatype (Size) foreign key (ColumnName) References TableName (ColumnName)
[On delete/Update Cascade]
Example:
Create table student (RollNo number (3) Primary key, Name varchar2 (15), Sid number (3)
foreign key (Sid) reference Subject (Sid)) on delete cascade;

On Delete Cascade
With this option, when any record from parent table is deleted, all the corresponding
records from child table are also deleted automatically.

Q.11 Explain different types of join with example.


Ans:
In DBMS it is possible to retrieve information from multiple table using join.
Join combines two or more tables.
Join combines columns from different tables.
There are different types of joins available in a SQL:
1. Cross Join (Cartesian product or simple join).
2. Inner Join (Equi join).
3. Self-Join
4. Outer Join

INNER JOIN
The inner join is the most common used join in all joins.
The inner join combines only that record which contains common value in both relations.
Inner join is totally reverse from cross join and it provides consistent record as an output.

Syntax:
Select column1, column2, colmunN from table1, table2 where table1.column1 op table2.column1;
In inner join, if both the columns are compared for equality (=op) then it is referred as ‘Equi
join’.
If both the columns are compared for non-equality, then join operation is referred as non-equi
join.

Example:
Relation: Student
ID NAME DEPT
1 Anisha CE
2 Tanisha EE

Relation: Hostel
NAME HOSTELNAME ROOMNO
Kanisha ABC 14
Anisha XYZ 12
Tanisha PQR 13

Example:

Select id, Student.Name, dept, RoomNo, HostelName form Student,Hostel where Student
Name=Hostel.Name;

Output:

ID NAME DEPT HOSTELNAME ROOMNO


1 Anisha CE XYZ 12
2 Tanisha EE PQR 13
OUTER JOIN:
 The outer join operation is an extension of inner join operation.
 In inner join operation, it may be possible to lose information.
 The outer join with such kind of missing information.
 Outer join operation can be divided into three different forms:
1. Left Outer Join
2. Right Outer Join
3. Full Outer Join

Q12. What is sub query? Explain with Example.


A Subquery is a SQL statement that contains one statement within another
statement.
A Subquery is a SQL query within in a Query.
Subquery must be enclosed within parentheses.
Syntax:
SELECT column_name [, column_name] FROM table1 [, table2] WHERE column_name
OPERATOR (SELECT column_name [, column_name] FROM table1 [, table2] [WHERE])

Example:
Id Name Dept Age Salary Location
100 Ramesh Electrical 24 2500 Bangalore
101 Hrithik Electronics 28 6500 Bangalore
102 Harsha Aeronautics 28 5500 Mysore
103 Soumya Electronics 22 2000 Bangalore
104 Priya InfoTech 25 3000 Mangalore

Example:
SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM CUSTOMERS
WHERE SALARY > 4500);

Output:

Id Name Dept Age Salary Location


101 Hrithik Electronics 28 6500 Bangalore
102 Harsha Aeronautics 28 5500 Mysore

Q13. List set operators and Explain all with Example.


Ans:
There are four types of Set operators.
1) Union
2) Union all
3) Intersect
4) Minus
UNION Clause
The UNION clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain all the records from query1 and query2 according to
following.
The number of columns, name of each column and their data types in both relations must be
same.
Syntax: SELECT * FROM table1 UNION SELECT * FROM table2;
Example: SELECT * FROM Emp UNION SELECT * FROM Cust;
Relation: Cust

ID Name
1 Manisha
2 Tanisha
3 Kavisha

Relation: Emp

ID Name
1 Manisha
2 Tanisha
4 Disha

Output:

ID Name
1 Manisha
2 Tanisha
3 Kavisha
4 Disha

UNION ALL Clause


The UNION ALL clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain all the records from query1 and query2 according to following.
The number of columns, name of each column and their data types in both relations must be
same.
Syntax: SELECT * FROM table1 UNION ALL SELECT * FROM table2;
Example: SELECT * FROM EMP UNION ALL SELECT * FROM Cust;
Relation: EMP
ID Name

1 Manisha

2 Tanisha

3 Kavisha
Relation: Cust

ID Name
1 Manisha
2 Tanisha
4 Disha

Output:

ID Name
1 Manisha
2 Tanisha
3 Kavisha
1 Manisha
2 Tanisha
4 Disha

1) INTERSECT Clause
 The Intersect clause merges the output of query1 and query2.
 The output will be as a single set of rows and columns.
 The output will contain those records which are common to query1 and query2
according to following.

 The number of columns, name of each column and their data types in both relations
must be same.
Output: A single set of Records which is common in both queries.
Syntax:

SELECT * FROM table1 INTERSECT SELECT * FROM table2;


 Example: SELECT * FROM Emp INTERSECT SELECT * FROM Cust;

Relation: Emp
ID Name
1 Manisha
2 Tanisha
3 Kavisha

Relation: Cust

ID Name
1 Manisha
2 Tanisha
4 Disha

Output:

ID Name
1 Manisha
2 Tanisha

1)
MINUS Clause
The MINUS clause merges the output of query1 and query2.
The output will be as a single set of rows and columns.
The output will contain those records which are present in query1 but not present in
query2 according to following.
 The number of columns, name of each column and their data types in both relations
must be same.

Syntax: SELECT * FROM table1 MINUS SELECT * FROM table2;


Example: SELECT * FROM EMP MINUS SELECT * FROM Cust;
Relation: Emp

ID Name
1 Manisha
2 Tanisha
3 Kavisha

Relation: Cust

ID Name
1 Manisha
2 Tanisha
4 Disha
Output:

ID Name
3 Kavisha

13 Explain types of keys with example.


Types of keys are:
1) Super Key
2) Candidate Key
3) Primary Key
4) Alternate Key
5) Foreign Key
1) Super Key
 "A super key is a set of one or more attributes that allows identifying each
tuple uniquely in a relation."
 Example: Relation student has Sid, sname, contact_no.
 Here, Sid, {Sid, sname} and contact_no is a super key.
2) Candidate Key
 Candidate key is a subset of super key.
 "If a relation contains more than one relation keys, then, they each are called
candidate key."
 A candidate key is a least combination of attributes that uniquely identify
each record in a relation.
 Example: Relation student has Sid, sname, contact_no.
 Here, Sid and contact_no is candidate key.
3) Primary Key
 "A primary key is a candidate key that is chosen by the database designer to
identify tuples uniquely in a relation."
Page 32
 A primary key is a candidate key that is most appropriate to become main
key for any relation.
 Example: Relation student has Sid, sname, contact_no.
 Here, Sid is a primary key.

4) Alternate Key
 "An alternate key is a candidate key that is not chosen by the database
designer".
 Candidate key which are not selected as a primary key are known as
alternate key or secondary key.
 Example: in above relation table Sid and phone is candidate key.
 Sid is a primary key so phone is an alternate key.
5) Foreign Key
 "A foreign key is a set of one or more attributes whose values are derived
from the key attribute of another relation."
 This key is used to join two more tables.
 Example: Account: ano, balance, bname
Branch: bname, baddress
 Here, bname is foreign key for Account table and primary key for Branch
table.

Q.14 Explain group function or aggregate function with example.


1) AVG()
 It returns average value of the specified column, ignoring NULL values.
Syntax: AVG (Column name)
Example: select AVG (sell_price) from Product_Master;
Output: 2012.345

2) MIN()
 It returns the minimum value in the specified column.
Syntax: MIN (column name)
Example: select MIN (sell_price) from Product_Master;
Output: 250

3) MAX()
 It returns the maximum value in the specified column.
Syntax: MAX (column name)
Example: select MAX (sell_price) from Product_Master;
Output: 1500

4) SUM()
 It returns the sum of values of the specified column.
Page 33
Syntax: SUM (column name)
Example: select SUM (salary) from salesman_master;
Output: 65000

5) COUNT()
 It returns the number of rows in specified column or the total number of
rows in the table.
Syntax: COUNT (column name)
Example: select COUNT (salesman_no) from salesman_master;
Output: 15

Syntax: COUNT (*)


Example: select COUNT (*) from
salesman_master; Output: 50

Q.15 Explain logical operators with example.


Ans:
There are three types of Logical Operators
1) The AND Operator
2) The OR Operator
3) The NOT Operator

1) The AND Operator


 The AND Operator is used to combine two or more conditions in WHERE Clause.
 It requires all the conditions to be true to consider entire clause true.
 Example:
SQL>select * from employee;

ENAME SALARY CITY


Preet 20000 Jamnagar
Parimal 15000 Rajkot
Khanjan 12000 Surat
Mehul 8000 Ahmedabad

SQL>select * from employee where city = 'jamnagar' AND salary > 15000;
ENAME SALARY CITY

Preet 20000 Jamnagar

Page 34
2) The OR Operator
 The OP operators is also used to combine two or more conditions in WHERE and HAVING
clauses.
 It requires any one condition to be true to consider entire clause
true. Example:
SQL>select * from employee where city = 'Rajkot' OR city = 'Surat'; ENAME SALARY
CITY

Parimal 15000 Rajkot


Khanjan 12000 Surat

3) The NOT Operator


 The NOT operator is used to negate the result of any condition or group of
conditions.
Example:
SQL>select * from employee where not (city =
'Ahmedabad'); ENAME SALARY CITY

Preet 20000 Jamnagar


Parimal 15000 Rajkot
Khanjan 12000 Surat

Page 35

You might also like