You are on page 1of 7

DEPARTMENT OF COMPUTER ENGINEERING

Academic Year 2023-2024


SUBJECT:- Database Management System (22319) Course Code/Sem: - CO3I (A+B+C)
 Questions for TWO marks.
Sr.
Question
No
1 1. List system privileges and object privileges.
2. Object privileges:- Insert, update delete, select
3. System Privileges:-create table, create view, create sequence, alter any table
2 Define Cursor. List the two types of cursor
Cursor: The Oracle Engine uses a work area for its internal processing in order to execute an SQL
statement. This work area is private to SQL‟s operations and is called a Cursor.
OR
A cursor is a temporary work area created in the system memory when a SQL statement is executed.
Types of cursor are:
1) Implicit cursor
2) Explicit cursor
3 What is Equi Join? Write syntax of Equi Join.
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,table_name2
WHERE table_name1.column_name=table_name2.column_name;
4 What are advantages of PL/SQL (write any two)?
Advantages of PL/SQL:
 PL/SQL is portable and high transaction processing language.
 It also supports object oriented programming.
 It allows user to write as well as access the functions and procedures from outside the programs.
 It has got built in libraries of packages
5 List any four PL/SQL data types.
Data Types in PL/SQL are used to define how the data will be stored, handled, and treated by Oracle
during the data storage and processing. Data types are associated with the specific storage format and
range constraints.
1. NUMBER or NUMBER(P,S)
2. PLS_INTEGER
3. CHAR
4. RAW
5. ROWID
6. VARCHAR2
7. DATE
6 Write a query to assign create, select,update privilege on empno column of emp table to ‘Rahul user.
GRANT Create,select, update(empno) ON emp TO Rahul;
7 Compare PL/SQL function and procedure (any TWO points).
Procedures Functions
Execute as a PL/SQL statement Invoke as part of an expression
Do not contain RETURN clause in the header Must contain a RETURN clause in the header
Can return none, one, or many values Must return a single value
8 List in-built functions in SQL.
The in-built functions in SQL are:
Single Row functions:
a. Character function
b. Date function
c. Numeric function
d. Conversion function
Aggregate functions:
a. SUM()
b. AVG()
c. MAX()
d. MIN()
e. COUNT(*),COUNT(columnName),COUNT(DISTINCT columnName)
9 Construct a SQL query to create user Rajan with password RAJAN449.
Create user Rajan
Identified by RAJAN449;
10 Explain subquery concept with example.
Subquery : A subquery is a query which is embedded within another query. The outer query is called as
main query and inner query is called as subquery
For Example: Select * from customer where age = ( Select min(age) from customer );
1. The above query will select all rows from customer table with minimum age.
11 List the causes of database failures.
Causes of failure are:
 System Crash
 User error
 Carelessness
 Intentional corruption of data(sabotage)
 Statement failure
 Network failure
 Natural physical disasters.
12 Draw states of transaction diagram.
13 Draw PL/SQL block structure.

14 Write syntax for creating synonyms with example.


Syntax to create synonym:
CREATE SYNONYM synonym_name
FOR Table_name;
Example to create synonym:
CREATE SYNONYM offices
FOR locations;
 Questions for FOUR marks
1 Construct a PL/SQL procedure to calculate factorial of a give number.
create or replace procedure Factorial(n in number)
is
v number :=1;
begin
for i in 1..n loop
v :=v * i;
end loop;
dbms_output.put_line(v);
end;
Procedure created
SQL> Begin
Factorial(5);
End;
2 Define index. Explain its types with the help of syntax and example.
An Index is a schema object. It is used by the oracle server to improve the speed of retrieval of the rows
from a table .Indexes are of two types based on number of columns included in the index.
The types of index are:
1) Simple index: An index created on a single column of table is called as simple index
Syntax:
SQL>Create Index index_name on tablename(attribute);
Example:Create index emp_index on emp(empno);
2) Composite Index: An index created on more than one column is called composite index.
Syntax:
SQL>Create Index index_name on tablename(attribute1,attribute2);
Example: Create index emp_index on emp(empno,ename);
3 Explain ACID properties of transaction.
TRANSACTION: A transaction is a unit of program execution that accesses and possibly updates
various data items. The transaction insists by all operations executed below the begin transaction and end
transaction.

ACID Properties of Transaction:


• Atomicity: Either all operations of the transaction are reflected properly in the database, or none.
• Consistency: Consistency ensures that the database is in consistent state prior and after the execution
of transaction. 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 database.
• Isolation: Even though multiple transactions may execute concurrently, the system guarantees that, for
every pair of transactions Ti and Tj , it appears to Ti that either Tj finished execution before Ti started, or
Tj started execution after Ti finished. Thus, each transaction is unaware of other transactions executing
concurrently in the system.
• Durability: After a transaction completes successfully, the changes it has made to the database persist,
even if there are system failures.

4 Explain any four aggregate functions with example.


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 :
1) Count()
2) Sum()
3) Avg()
4) Min()
5) Max()
1. Count () - 1) It returns number of rows from the given table if no attribute is mentioned.
2) If some attribute is mentioned, it gives total number of not null values for that attribute.
Ex :Select count(*) from emp;
Returns total number of records from emp table.
1) Select count(telephone) from emp;
Returns total number of employees having telephone numbers.
2. Sum() - It give total of all values from a numeric attribute of the given table,
Ex :Select sum(salary) from emp;
Returns total salary drawn of all employees from the emp table.
3. Avg () - It gives average of all the numeric values of the given attribute from the table.
Ex :Select Avg(salary) from emp;
Returns average salary of employees from emp table.
4. Min () - It gives minimum of all the values of the numeric given attribute from the table.
Ex :Select Min(salary) from emp;
Returns minimum salary value from emp table,
5. Max () - It gives maximum of all the values of the numeric given attribute from the table.
Ex :Select Max(salary) from emp;
retunes maximum salary value from emp table,
5 Consider following schema.EMPLOYEE-DETAILS (empname, empId, DOB, salary, job).Build a
view on EMPLOYEE_DETAILS having attribute(empname, empId, DOB, salary, job) where
salary is greater than 20,000.
Create view v_employee_details
As
select * from employee_details where salary >20000;
6 Construct a PL/SQL function to find the area of circle & define Pi as constant.
Create or replace function circle_area(r number)
return number
is
area number;
Pi constant number(3,2):=3.14;
BEGIN
area := pi*r*r;
return area;
END circle_area;
7 Consider the structure for book table as Book_master {book_id, book_name, subcode, author,
no_of_copies, price,return_date}. Construct SQL queries for the following:
i) Display total no. of book for subject ‘DBM’.
Select count(book_id) from book_master where book_name= „DBM‟;
ii) Get authorwise list of all books.
Select * from book_master order by author;
iii) Display return date as 01 January,2019.
Select to_char(return_date, „dd Month, yyyy.‟) from book_master;
iv)Display the details of books in increasing order of price.
Select * from book_master order by price asc;
8 Write SQL queries for following. Consider table stud (roll no, name, subl, sub2, sub3)
i) Display names of student who got minimum mark in sub1.
ii)Display count of Students failed in sub2.
iii) Display average marks of subl of all students.
iv)Display names of students whose name start with 'A' by arranging them in ascending order of
subl marks.
i. select name from stud where sub1= (select min(sub1) from stud);
ii. select count(*) from stud where sub2 <40;
iii. select avg(sub1) from stud;
iv. select name from stud where name like 'A%' order by sub1;
9 Perform the following operations on table student
i) Construct a view Stud_view having marks greater than 80.
ii) Permanently delete Stud_view
Ans. i) CREATE VIEW Stud-view AS SELECT * FROM student WHERE marks >80;
(ii)DROP VIEW Stud-view
10 Explain any four string functions with example.
It accepts character input and returns either character or number.
Sr. Function Description
No
1. Initcap(char) Converts first letter of string to capital letter.
Example: Select initcap(„rdbms‟) from dual;
2. Lower(char) Converts a string to all lowercase characters.
Example: Select lower(„RDBMS‟) from dual;
3. Upper(char) Converts a string to all uppercase characters.
Example: Select upper(„rdbms‟) from dual;
4. Length(char) Find outs the length of given string.
Example: Select length(„RDBMS‟) from dual;
5. Ltrim(char,set) It trim from the left of character string.
Example: Select Ltrim(„manas khan‟, „manas‟) from dual;
6. It trim from the Right of character string.
Rtrim(char,set) Example: Select Rtrim(„manas khan‟, „khan‟) from dual;
7. It returns char1, left-padded to given length with the sequence of characters in char2.
Lpad(char1,length, char2)
Example:
Select Lpad(„SKY‟, 8, „=‟) from dual;
8. It returns char1, right-padded to given length with the sequence of characters in
Rpad(char1,length ,char2) char2.
Example:
Select Rpad(„SKY‟, 8, „=‟) from dual;
9. It returns expr with all occurrences of each character in from_string replaced by its
corresponding character in to_string.characters in expr that are not in from_string
Translate(char,from string, to
are not replaced.
string)
Example:
Select translate(„hickory‟,‟h‟,‟D‟) from dual;
10. It returns character string with each occurrence of searching replaced with to string
Replace(char,from string,to
Example:
string)
Select replace(„Tick and Tock‟,‟T‟,‟Cl‟) from dual;
11. It returns substring of character string that stack at m character and is of length n
Substr(char,m,n) Example:
Select substr(„triangle‟, 4, 5) from dual;
12. It merges two or more strings or a string and a data value together
Concatenation(||) Example:
Select ename ||‟is a‟||job from emp;
11 Explain database backups with its types.
Regular backups are required to protect database and ensure its restoration in case of failure. Various
backup types provide different protection to our database. Backing up and restoring data is one of the
most important responsibilities of IT professionals
Three common types of database backups can be run on a desired system:
Normal (full), Incremental and Differential.
i) Normal or Full Backups:
When a normal or full backup runs on a selected drive, all the files on that drive are backed up. This, of
course, includes system files, application files, user data — everything. Those files are then copied to the
selected destination (backup tapes, a secondary drive or the cloud), and all the archive bits are then
cleared. Normal backups are the fastest source to restore lost data because all the data on a drive is saved
in one location.
ii) Incremental Backups:
A common way to deal with the long running times required for full backups is to run them only on
weekends. Many businesses then run incremental backups throughout the week since they take far less
time. An incremental backup will grab only the files that have been updated since the last normal
backup. Once the incremental backup has run, that file will not be backed up again unless it changes or
during the next full backup.
iii) Differential Backups:
An alternative to incremental database backups that has a less complicated restore process is a
differential backup. Differential backups and recovery are similar to incremental in that these backups
grab only files that have been updated since the last normal backup.
However, differential backups do not clear the archive bit. So a file that is updated after a normal backup
will be archived every time a differential backup is run until the next normal backup runs and clears the
archive bit.
12 Explain group by and order by clause with the help examples.
Group by Clause:
Group by clause is used to collect the data as multiple records and group them to
produce the result.
Syntax:
SELECT column_name, function(column_name)
FROM table_name
WHERE condition
GROUP BY column_name;
Example: SELECT avg(sal) FROM emp_details GROUP BY deptno;
Order by Clause:
To view the data in sorted order, the order by clause is used.
By default, the data is sorted in ascending order.
Syntax:
SELECT expressions
FROM tables
[WHERE conditions]
ORDER BY expression [ ASC | DESC ];
Example: SELECT deptno FROM emp_details ORDER BY deptno;
Example: SELECT deptno FROM emp_details ORDER BY deptno desc; (for descending order)

You might also like