0% found this document useful (0 votes)
67 views20 pages

Sy Dip - Dbms Super 25 With Answer by Shivam Sir

The document provides a comprehensive set of 25 questions and answers related to Database Management Systems (DBMS), covering topics such as data abstraction, normalization, SQL syntax, database architecture, and transaction properties. It includes practical SQL queries, PL/SQL code examples, and explanations of database concepts like joins, triggers, and recovery techniques. The content serves as a study guide for understanding key DBMS principles and practices.

Uploaded by

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

Sy Dip - Dbms Super 25 With Answer by Shivam Sir

The document provides a comprehensive set of 25 questions and answers related to Database Management Systems (DBMS), covering topics such as data abstraction, normalization, SQL syntax, database architecture, and transaction properties. It includes practical SQL queries, PL/SQL code examples, and explanations of database concepts like joins, triggers, and recovery techniques. The content serves as a study guide for understanding key DBMS principles and practices.

Uploaded by

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

V2V EdTech LLP | DBMS | Super 25 Questions with Solution

V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Q1. Define Data Abstraction and Instance. Q2. Define : i)


Candidate key ii) Primary key. Q3. State any two advantages of
DBMS. Q4. Define Normalization. Enlist its types.
Q5. Write syntax for creating and Renaming a table. Q6. Write
syntax for creating and dropping views.
Q7. Write down any four Dr. E.F Codd's rules.
Q8. List disadvantages of typical file processing system. Q9. State
the use of group by and order by clauses.
Q10. Describe commit and rollback with syntax and example Q11.
Draw the overall architecture of DBMS. Explain storage manager
and query processor components.
Q12. Enlist any four aggregate functions.
ANS:
An aggregate function is a function where the values of multiple
rows are grouped together as input on certain criteria to form a
single value of more significant meaning. Aggregate functions are
:

Count()
Sum()
Avg()
Min()
Max()

1. Count () : It returns number of rows from the given table if no


attribute is mentioned.
If some attribute is mentioned, it gives total number of not null
values for that attribute.
Eg : Select count(*) from emp;
Returns total number of records from emp table.
Select count(telephone) from emp;
Returns total number of employees having telephone numbers.
2. 2. Sum() : It give total of all values from a numeric attribute of
the given table.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution
Eg : Select sum(salary) from emp;
Returns total salary drawn of all employees from the emp table.
Avg () : It gives average of all the numeric values of the given
attribute from the table.
Eg :Select Avg(salary) from emp;
Returns average salary of employees from emp table.
Min () : It gives minimum of all the values of the numeric given
attribute from the table.
Eg :Select Min(salary) from emp;
Returns minimum salary value from emp table.
Max () : It gives maximum of all the values of the numeric given
attribute from the table.
Eg :Select Max(salary) from emp; retunes maximum salary value
from emp table,

Q13. Explain Cursor. List the two types of cursor.


ANS:
A cursor is a temporary work area created in system memory
when a SQL statement is executed. A cursor is a set of rows
together with a pointer that identifies a current row. It is a
database object to retrieve data from a result set one row at a
time. It is useful when we want to manipulate the record of a
table in a singleton method, in other words one row at a time. In
other words, a cursor can hold more than one row, but can
process only one row at a time. The set of rows the cursor holds
is called the active set.

Implicit cursor: these types of cursors are generated and used by


the system during the manipulation of a DML query. An implicit
cursor is also generated by the system when a single row is
selected by a SELECT command. Programmers cannot control the
implicit cursors.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution
Explicit cursor: this type of cursor is created by the user when the
select command returns more than one row, and only one row is
to be processed at a time. An explicit cursor can move from one
row to another in a result set. An explicit cursor uses a pointer
that holds the record of a row.

To create an explicit cursor the following steps are used:

1. Declare cursor: this is done in the declaration section of PL/SQL


program.
Open: this step is done before the cursor is used to fetch the
records.
Fetch: used to retrieve data row by row from the cursor.
Close: once the processing of the data is done, the cursor can be
closed.

Example:
declare
name emp_details.ename%type;
cursor a is select ename from emp_details where
empno=3;//cursor declaration
begin
open a;//opening the cursor
loop
fetch a into name;//fetching the rows from cursor
update emp_details set comm=3000 where empno=3;
exit when a%notfound;
dbms_output.put_line('record updated');
end loop;
close a;//closing the cursor
end;

Q14. Enlist arithmetic and logical SQL operators.


ANS:
SQL Arithmetic Operators:
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Addition Operator(+)
Multiplication Operator (-)
Division Operator (/)
Modulus Operator (%)

SQL Logical Operators:

AND operator
OR operator
BETWEEN operator
IN operator
NOT operator
ANY operator
LIKE operator

Q15. Explain three level architecture of Database system.


ANS:

This architecture has three levels:


V2V EdTech LLP | DBMS | Super 25 Questions with Solution

External level
Conceptual level
Internal level

External level

It is also called view level because several users can view their
desired data from this level which is internally fetched from
database with the help of conceptual and internal level mapping.
The user doesn’t need to know the database schema details such
as data structure; table definition etc. user is only concerned
about data which is what returned back to the view level after it
has been fetched from database which is present at the internal
level. External level is the top level of the three level DBMS
architecture.

Conceptual level

It is also called logical level. The whole design of the database


such as relationship among data, schema of data etc. are
described in this level. Database constraints and security are also
implemented in this level of architecture.
This level is maintained by DBA (database administrator)

Internal level

This level is also known as physical level. This level describes how
the data is stored in the storage devices. This level is also
responsible for allocating space to the data. This is the lowest
level of the architecture.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution
Q16. Write SQL queries for following: i) Create table student with
following attributes using suitable data types. Roll no., as primary
key, name, marks as not null and city. ii) Add column Date of
Birth in above student table. iii) Increase the size of attribute
name by 10 in above student table. iv) Change name of Student
table to stud.

ANS:

i) CREATE TABLE Student


(
Rollno int PRIMARY KEY,
name varchar(30) NOT NULL,
marks int NOT NULL,
city varchar(20)
);
ii) ALTER TABLE student ADD DateofBirth varchar(20);
iii) ALTER TABLE student Modify name varchar(40);
iv) RENAME Student to Stud;

Q17.Write and Explain the syntax for creating and dropping


indexes with an example.
ANS:

CREATE INDEX

The CREATE INDEX command is used to create indexes in tables.


It allows duplicate values. Indexes are used to retrieve data from
the database very fast. The users cannot see the indexes; they
are just used to speed up searches/queries.

Syntax:
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

CREATE INDEX index_name


ON table_name (column1, column2, ...);

Example:

The following SQL creates an index named id_firstname on the


FirstName column in the Student table:

CREATE INDEX id_firstname ON Student (FirstName);

DROP INDEX

The DROP INDEX statement is used to delete an index in a table


.
Syntax:
DROP INDEX index_name ON table_name;

Example:
DROP INDEX id_firstname ON Student;

Q18. Write a PL/SQL code to print reverse of a number.


ANS:

declare

n number;
i number;
rev number:=0;
r number;

begin

n:=&n;
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

while n>0 loop

r:=mod(n,10);
rev:=(rev*10)+r;
n:=trunc(n/10);

end loop;

dbms_output.put_line('reverse is '||rev);
end;

Q19. Distinguish between network model and hierarchical model.


ANS :
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Q20. Describe exception handling in brief.


ANS:
Exception Handling: Exception is nothing but an error. Exception
can be raise when DBMS encounters errors or it can be raised
explicitly.

When the system throws a warning or has an error it can lead to


an exception. Such exception needs to be handled and can be
defined internally or user defined.

Exception handling is nothing but a code block in memory that


will attempt to resolve current error condition.

Syntax:

DECLARE ;
Declaration section
…executable statement;
EXCEPTION
WHEN ex_name1 THEN ;
Error handling statements/user defined action to be carried out;
END;

Types of Exception:

Predefined Exception/system defined exception/named


exception:
Are always automatically raised whenever related error occurs.
The most common errors that can occur during the execution of
PL/SQL. Not declared explicitly i.e. cursor already open, invalid
cursor, no data found, zero divide and too many rows etc.
Programs are handled by system defined Exceptions.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

User defined exception:


It must be declare by the user in the declaration part of the block
where the exception is used. It is raised explicitly in sequence of

statements using: Raise_application_error(Exception_Number,


Error_Message);

Q21. Explain joins in SQL with examples.


ANS:

JOIN:

A SQL join is an instruction to combine data from two sets of data


(i.e. two tables).A JOIN clause is used to combine rows from two
or more tables, based on a related column between them. SQL
Join types are as follows:
INNER JOIN or EQUI JOIN: A join which is based on equalities is
called equi join. In equi join comparison operator “=” is used to
perform a Join.

Syntax:
SELECT tablename.column1_name,tablename.column1_name
FROM table_name1 inner join table_name2 ON
table_name1.column_name=table_name2.column_name;

Example:
Select stud_info.stud_name, stud_info.branch_code,
branch_details.location From stud_info inner join branch_details
ON Stud_info.branch_code=branch_details.branch_code;

2. LEFT OUTER JOIN: A left outer join retains all of the rows of
the “left” table, regardless of whether there is a row that
matches on the “right” table.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Syntax:

Select column1name,column2name from table1name left outer


join table2name on table1name.columnname=
table2name.columnname;

Example:

select last_name, department_name from employees left outer


join departments on employees.department_id =
departments.department_id;

3) RIGHT OUTER JOIN: A right outer join retains all of the rows of
the “right” table, regardless of whether there is a row that
matches on the “left” table.

Syntax:

Select column1name, column2name from table1name any_alias1


right outer join table2 name any_alias2 on
any_alias1.columnname =any_alias2.columnname;

Example:

Select last_name, department_name from employees e right


outer join departments d on e.department_id = d.department_id;

Q22. Explain function in PL/SQL with example.


ANS:

Function: Function is a logically grouped set of SQL and Pl/SQL


statements that perform a specific task.
A function is same as a procedure except that it returns a value. A
function is created using the CREATE FUNCTION statement.

Syntax:
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

CREATE [OR REPLACE] FUNCTION function_name


[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN < function_body >
END [function_name];

Example:

CREATE OR REPLACE FUNCTION Success_cnt


RETURN number
IS cnt number(7) := 0;
BEGIN SELECT count(*) into cnt
FROM candidate where result='Pass';
RETURN cnt;
END;

Q23. Explain ACID properties of transaction.


ANS:
ACID properties of transaction

1. Atomicity: When one transaction takes place, many operations


occur under one transaction. Atomicity means either all
operations will take place property and reflect in the database or
none of them will be reflected.

2. Consistency: Consistency keeps the database consistent.


Execution of a transaction needs to take place in isolation. It
helps in reducing complications of executing multiple
transactions at a time and preserves the consistency of the
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

database.

3. Isolation: It is necessary to maintain isolation for the


transactions. This means one transaction should not be aware of
another transaction getting executed. Also their intermediate
result should be kept hidden.

4. Durability: When a transaction gets completed successfully, it


is important that the changes made by the transaction should be
preserved in database in spite of system failures.

Q24. Describe any four responsibilities of Database


administrator.
ANS:

Responsibilities of Database Administrator (DBA):

1. Schema Definition: Database or schema can be designed or


defined by DBA.
2. Creating storage structure: DBA allocate or decide the space
to store the database.
3. Create grant access methods: Different access methods to
access the database can be granted by DBA to the users.
4. Schema modification: The database or schema which is
already defined can be modified by DBA as per the requirements.
5. Granting authorization: To access the different databases, DBA
can grant the authorization to authorized users only.
6. Performance tuning: The problems/errors arise in database
accessing; can be resolved by DBA to increase the performance.
7. Regular maintenance: DBA can monitor the transactions in
database and maintain the database error free by doing the
regular maintenance.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Q25. Write and Explain the syntax for creating database trigger.
ANS:

Database trigger:
Triggers can be referred as stored procedures that are fired or
executed when an INSERT, UPDATE or DELETE statement is given
against the associated table.

Syntax:

create trigger [trigger_name]


[before | after]
{insert | update | delete}
on [table_name]
[for each row]
[trigger_body]

Example:

Given Student Report Database, in which student marks


assessment is recorded. In such schema, create a trigger so that
the total and percentage of specified marks is automatically
inserted whenever a record is insert.
Here, as trigger will invoke before record is inserted so, BEFORE
Tag can be used.

create trigger stud_marks


before
INSERT
on Student
for each row
set Student.total = Student.subj1 + Student.subj2 +
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Student.subj3, Student.per = Student.total * 60 / 100;

Q26. Explain Database Recovery techniques in detail.


ANS:

Database Recovery Techniques:


Database recovery techniques are used to restore the original
data in system from backup. Backward and forward recovery is
two types of database recovery.

Recovery Techniques:
1. Log based recovery.
2. Shadow paging recovery
3. Checkpoints

1. Log based recovery: It records sequence of log records, which


includes all activities done by database users.
It records the activities when user changes the database.
In case of database failure, by referring the log records users can
easily recover the data.

2. Shadow paging recovery: This technique is the alternative for


log based recovery.
In this technique, database is divided into pages that can be
stored on the disk.
The page table is used to maintain the record of location of
pages. In case of database failure, page table is used to recover
the parts of database.

3. Checkpoints: Checkpoint records all committed transactions


into logs.
When system fails, it check log to determine recovery action.
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Q27. Write the SQL queries for following EMP table. Emp
(empno, deptno, ename, salary, designation, city.) i) Display
average salary of all employees. ii) Display names of employees
who stay in Mumbai or Pune. iii) Set the salary of employee
'Ramesh' to 50000. iv)Display names of employees whose salaries
are less than 50000. v) Remove the Record of employees whose
deptno is 10. vi) Remove the column deptno from EMP table.
ANS:
i. select avg(salary) from emp;
ii. select ename from emp where city=’Mumbai’ or city=’Pune’;
iii. update emp set salary=50000 where ename=’Ramesh’;
iv. select ename from emp where salary<50000;
v. delete from emp where deptno=10;
vi. alter table emp drop column deptno;

Q28. Write and Explain the syntax for creating, Altering and
dropping the sequence.
ANS:
Syntax for creating sequence:

CREATE SEQUENCE sequence_name


START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum value
MAXVALUE maximum value
CYCLE|NOCYCLE ;

Example:

CREATE SEQUENCE sequence_1


start with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

Alter sequence:

Syntax:
alter sequence <sequence name> maxvalue <number>;
Alter sequence can change the maxvalue in the sequence
created.

Dropping sequence:
Syntax:
drop sequence <sequenc name> ;
To drop the sequence the DROP command is used

Q29. Explain View with example.


ANS:

A view is like a window into the data stored in a database. It


doesn’t actually store any data on its own. Instead, it shows data
from one or more tables based on a query (a question or request
for information). You can think of it like a saved search or a
shortcut that you can use over and over again to get certain
information.

When you use a view, it looks like you’re working with a regular
table, but in reality, the database just runs the query behind the
scenes and gives you the result.

· Virtual Table: A view is not a real table; it only represents data


from existing tables.
· Read-Only or Updatable: Depending on the complexity of the
view, it can be read-only (if it involves complex joins or
aggregations) or updatable (if it's a simple query on a single
table).
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

· Simplifies Queries: Views can encapsulate complex queries,


making them easier to reuse.
· Security: Views can be used to restrict access to specific
columns or rows of data.

Example :

CREATE VIEW EmployeeDetails AS


SELECT e.Name, d.DepartmentName, e.Salary
FROM Employees e
JOIN Departments d ON e.Department = d.DepartmentName;

Q30. Explain Index and its type with example?


ANS:

An index in a database is like a bookmark or table of contents


that helps the database find and access data faster. Instead of
searching through all the rows in a table, the database can use
the index to quickly locate the data you need.

Types of Indexes:

1. Single-column Index: An index created on just one column of a


table.

Syntax :

CREATE INDEX idx_student_id ON Students(student_id);

2. Multi-column Index (Composite Index): An index created on


multiple columns. It helps when you often query based on more
than one column.

Syntax :
V2V EdTech LLP | DBMS | Super 25 Questions with Solution

CREATE INDEX idx_name ON Students(first_name, last_name);

3. Unique Index: Ensures that all values in the indexed column(s)


are unique. It’s automatically created when you define a primary
key or unique constraint.

Syntax:

CREATE UNIQUE INDEX idx_unique_student_id ON


Students(student_id);

You might also like