0% found this document useful (0 votes)
741 views23 pages

S-24

Uploaded by

pranav.s.p759
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)
741 views23 pages

S-24

Uploaded by

pranav.s.p759
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/ 23

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

Important Instructions to examiners:


1) The answers should be examined by key words and not as word-to-word as given in the
model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may
try to assess the understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more
Importance (Not applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in
the figure. The figures drawn by candidate and model answer may vary. The examiner
may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed
constant values may vary and there may be some difference in the candidate’s answers
and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of
relevant answer based on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi
and Bilingual (English + Marathi) medium is introduced at first year of AICTE diploma
Programme from academic year 2021-2022. Hence if the students in first year (first and
second semesters) write answers in Marathi or bilingual language (English +Marathi), the
Examiner shall consider the same and assess the answer based on matching of concepts
with model answer.

Q. Sub Answer Marking


No Q.N. Scheme
1. Attempt any FIVE of the following: 10
a) Define Normalization. List its types. 2M
Ans. Normalization is a process of decomposing the relations into relations
with fewer attributes.Normalization is used to minimize the Definition 1M
redundancy from a relation or set of relations and also used to
eliminate undesirable characteristics like Insertion, Update, and Types 1M
Deletion Anomalies.
Types:
1. First Normal Form (1NF)
2. Second Normal Form (2NF)
3. Third Normal Form (3NF)
4. Boyce Codd's Normal Form (BCNF)
5. Fourth Normal Form (4NF)
6. Fifth Normal Form (5NF)

Page 1 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

b) List disadvantages of typical file processing system 2M


Ans. 1. Data redundancy: Data redundancy refers to the duplication of
data which often leads to higher storage costs and poor access Any 4
disadvantages
time. ½M each
2. Data inconsistency: Data redundancy leads to data inconsistency.
Same data at multiple places can lead to inconsistent output in
case of update, and delete anomalies.
3. Data Isolation: Because data are scattered in various files, and
files may be in different formats, writing new application
programs to retrieve the appropriate data is difficult.
4. Dependency on application programs: Changing files would lead
to change in application programs.
5. Atomicity issues: Atomicity of a transaction refers to “All or
nothing”, which means either all the operations in a transaction
executes or none.
6. Data Security: Security constraints are difficult to apply in file
processing systems.

c) List system privileges and object privileges 2M


Ans. System privileges:
1. CREATE: creates the database objects System
privileges 1M
2. ALTER: alters/ modifies the database objects
3. DROP: drops or deletes the database objects.
Object privileges: Object
1. READ or SELECT lets you access an object and its attributes privileges 1M
from the table.
2. UPDATE lets you modify attributes of objects in the table.
3. INSERT lets you add new objects to the table.
4. DELETE lets you delete objects from the table.

d) State the causes of database failure 2M


Ans. 1. Failure of a transaction or program: If a transaction that is in
progress fails due to an internal issue. Any 2 causes
1M each
2. Total system failure: If the system crashes or gets damaged.
3. Failure of hardware: If the hardware fails on which the
database is stored.

e) Define: 2M
i) Data Abstraction
ii) Data Redundancy
Page 2 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

Ans. i) Data Abstraction: Data abstraction in DBMS means hiding Each


unnecessary background details from the end user to make the definition 1M
accessing of data easy and secure.

ii) Data Redundancy: Data redundancy in a Database Management


System (DBMS) refers to the repetition of the same data in multiple
places within a database.

f) List date and time functions 2M


Ans. ADDDATE() Add time values (intervals) to a date value
Any 2 date
functions 1M
ADDTIME() Add time
Any 2 time
DATE() Extract the date part of a date or datetime functions 1M
expression
DATE_ADD() Add time values (intervals) to a date value

DATE_FORMAT() Format date as specified


DATE_SUB() Subtract a time value (interval) from a date

DATEDIFF() Subtract two dates


DAY() Synonym for DAYOFMONTH()
DAYNAME() Return the name of the weekday
DAYOFMONTH() Return the day of the month (0-31)

DAYOFWEEK() Return the weekday index of the argument

DAYOFYEAR() Return the day of the year (1-366)


HOUR() Extract the hour
MAKEDATE() Create a date from the year and day of year

Page 3 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

MAKETIME() Create time from hour, minute, second

MINUTE() Return the minute from the argument

MONTH() Return the month from the date passed

NOW() Return the current date and time


TIMEDIFF() Subtract time
WEEK() Return the week number
YEAR() Return the year

g) Define: 2M
i) Instance
ii) Schema Each
Ans. i) Instance: An instance in DBMS is essentially a snapshot of the definition 1M
data stored in a database at a specific point in time.

ii) Schema: The overall design of the database is called database


schema.
2. Attempt any THREE of the following: 12
a) Explain set operators with example 4M
Ans. 1. UNION
2. UNION ALL Each operator
with example
3. INTERSECT
1M
4. MINUS

UNION Operation:
UNION is used to combine the results of two or more SELECT
statements. However it will eliminate duplicate rows from its
resultset. In case of union, number of columns and data type must be
same in both the tables, on which UNION operation is being applied.
SELECT * FROM employee
UNION
SELECT * FROM Worker;

Page 4 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

UNION ALL:
This operation is similar to Union. But it also shows the duplicate
rows.
SELECT * FROM employee
UNION ALL
SELECT * FROM Worker;

INTERSECT:
Intersect operation is used to combine two SELECT statements, but it
only returns the records which are common from both SELECT
statements.
SELECT * FROM employee
Intersect
SELECT * FROM Worker;

MINUS:
The Minus operation combines results of two SELECT statements
and return only those in the final result, which belongs to the first set
of the result.
SELECT * FROM employee
Minus
SELECT * FROM Worker;

b) Differentiate between network model and hierarchical model 4M


Ans.
Sr. Hierarchical Data Model Network Data Model Any 4 correct
No points 1M
each
1. In this model, to store data In this model, you could
hierarchy method is used. create a network that shows
how data is related to each
other.
2. It implements 1:1 and 1:n It implements 1:1, 1:n and
relations. also many to many relations.
3. To organize records, it uses To organize records, it uses
tree structure. graphs.
4. Records are linked with the Records are linked with the
help of pointers. help of linked list.

Page 5 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

5. Insertion anomaly exits in There is no insertion


this model i.e. child node anomaly.
cannot be inserted without
the parent node.
6. Deletion anomaly exists in There is no deletion
this model i.e. it is difficult anomaly.
to delete the parent node.
9. This model lacks data There is partial data
independence. independence in this model.
10. Less flexible in comparison It is flexible.
to the relational model.
11. When you are searching for Searching for a record is
a record then firstly you easy because of the
need to visit parent record availability of multiple
before retrieving a child access paths to reach data
record. item.
c) Write query using group by and having clause (use students 4M
database)
Ans. Note: Any other relevant query shall be considered Correct logic
2M
Select course, count (*) from student group by course having Correct syntax
course_id>=20 2M
d) Write PL/SQL code to print largest number from three numbers 4M
(Accept 3 numbers from user)
Ans. Correct logic
declare 2M
a number(2);
b number(2); Correct syntax
c number(2); 2M
begin
a:=&a;
b:=&b;
c:=&c;
if a>b and a>c then
dbms_output.put_line('Largest No = '||a);
elsif b>c then
dbms_output.put_line('Largest No = '||b);
else
dbms_output.put_line('Largest No = '||c);
end if;
end;

Page 6 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

3. Attempt any THREE of the following: 12


a) Write and explain syntax for creating and dropping synonyms 4M
with example
Ans. Create Synonym Create
Syntax: synonym
syntax with
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema.] explanation
synonym_name 1M
FOR [schema.] object_name;
OR Example 1M
create synonym synonym_name for object_name;

OR REPLACE Allows you to create synonym (if it already exists) Drop synonym
without having to issue a DROP command. syntax with
explanation
PUBLIC :Creates a synonym accessible to all users. 1M,
object_name: The name of object for which you are creating the
synonym. It can be table, view, sequences, stored procedure, function, Example 1M
synonym and other database object.

Example: CREATE OR REPLACE PUBLIC SYNONYM staff FOR


university.Employee;

Drop synonym
Syntax: drop synonym <synonym_name>;

Example: drop synonym employee;

b) State and explain 1NF and 2NF with example 4M


Ans. Note: Any other relevant example shall be considered
First Normal Form (1NF): A relation R is said to be in first normal Each
form (1NF) if the domain of all attributes of R are atomic. Explanation
OR 1M

A table is in the first normal form if it contains no repeating elements Each


Example
groups.
1M
Example: Supplier(sno, sname, location, pno, qty)

Page 7 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

SNO SNAME LOCATION PNO QTY


S1 Abc Mumbai P1 200
S2 Pqr Pune P2 300
S3 Lmn Delhi P1 400
Supplier
The above relation is in 1NF as all the domains are having atomic
value. But it is not in 2NF.

Second Normal Form (2NF): A relation is said to be in the second


normal form if it is in first normal form and all the non key attributes
are fully functionally dependent on the primary key.
Example: In the above relation NAME, LOCATION depends on
SNO and QTY on
(SNO, PNO) so the table can be split up into two tables as
Supplier(SNO, SNAME, LOCATION) and SP(SNO, PNO, QTY)
and now both the tables are in second normal form.

Supplier
SNO SNAME LOCATION
S1 Abc Mumbai

S2 Pqr Pune
S3 Lmn Delhi

SP

SNO PNO QTY


S1 P1 200

S2 P2 300
S3 P1 400

Page 8 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

c) Explain overall structure of DBMS with the help of diagram. 4M


Ans. Components of DBMS structure are classified in 3 categories as:
1. Query processor: Explanation
2M
Embedded DML pre compiler: It converts DML statements Diagram
embedded in application. Program to normal procedural calls in host 2M
language.

DML Compiler: It translates DML statements of high level language


into low level instruction that a query evaluation engine understands.

DDL interpreter: It interprets DDL statements and records them in a


set of tables containing metadata.

Query evaluation Engine: It executes low level instructions


generated by DML compiler and issued by query processor to select
efficient ways to execute query.

2. Storage Manager Components:

Transaction manager: It ensures that the database remains in


consistent state despite of the system failure and that concurrent
transaction execution proceeds without conflicting.

File Manager: It manages the allocation of space on disk storage and


data structures used to represent information stored on disk

Buffer Manager: It is responsible for fetching data from disk storage


into main memory and deciding what data to cache memory.

Authorization and Integrity Manager: It tests for the satisfaction of


integrity constraints checks the authority of users to access data.

3. Disk Storage:
Data files: It stores the database.
Data Dictionary: It stores metadata that hold particular values.
Indices: Provide fast access to data items that hold particular values.
Statistical data: It stores statistical information about the data in the
database.

Page 9 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

d) Write PL/SQL program to print number of employee working in 4M


specified department consider emp table and accept dept-no.
from user. Block variable
Ans. SET SERVEROUTPUT ON; declaration
1M
DECLARE
v_dept_noemp.dept_no%TYPE; Accept
v_emp_count NUMBER; dept_no 1M
BEGIN
-- Accept department number from the user
v_dept_no := &dept_no;

Page 10 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

-- Retrieve count of employees in the specified department Retrive emp


count query
SELECT COUNT(*) 1M
INTO v_emp_count
FROM emp
WHERE dept_no = v_dept_no;

-- Print the count of employees Display emp


DBMS_OUTPUT.PUT_LINE('Number of employees in count : 1M
department ' || v_dept_no || ': ' || v_emp_count);
EXCEPTION
(Exception
WHEN NO_DATA_FOUND THEN block is
DBMS_OUTPUT.PUT_LINE('No employees found in optional)
department ' || v_dept_no);
END;

4. Attempt any THREE of the following: 12


a) Write and explain syntax to create, open and close cursor in 4M
PL/SQL
Ans. 1. Cursor Declaration: Cursor
A cursor is defined in the declarative block of PL/SQL block. declaration
2M
This is done by naming the cursor and mapping it to query.
Syntax: Open cursor
CURSOR cursorname IS select statement. 1M

2. Opening a cursor. Close Cursor


1M
An opening a cursor executes the query and creates active set that
contains all rows.
Syntax:
Open cursorname;

3. Closing a cursor.
The close statement disables the cursor and active set becomes
undefined. This will release the memory occupied by cursor and
its dataset both on the client and on the server.
Syntax:
CLOSE cursorname;

Page 11 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

b) Differentiate between delete and truncate command with example 4M


Ans. Delete Truncate
Any 2 correct
DML command DDL command differences
The DELETE command is used The TRUNCAE used to remove 2M
to remove specific rows or all all the rows from table.
the rows depending upon our
environment
It can use the WHERE clause. It can‟t use the WHERE clause.
Removes the row one by one, Removes the rows at a time,
hence it is comparatively slower. hence It is faster.
Delete trigger will get fired No trigger will get invoked
ROLLBACK command can be ROLLBACK command cannot
used to get deleted record. be used to get records. New
records can be added into a table
as structure remains intact. Each
command
Example 1M
Example :Delete command
Delete command is used to delete rows in a table.
a. To delete all rows from the table
Syntax: Delete from<table name>;
Example : Delete from student;
Above command delete all tuples of student
b. To delete specific rows from the table.
Syntax: Delete from<table name> where <search_condition>;
Example: Delete from student where sid=’101;

Example:
Syntax :truncate table <tablename>;
Example :truncate table emp;

c) Explain any four joins if SQL with examples 4M


Ans. Note: Any other relevant example shall be considered Any 4 types,
JOIN: Each
description
A SQL join is an instruction to combine data from two sets of with Example
data (i.e. two tables). A 1M
JOIN clause is used to combine rows from two or more tables,

Page 12 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

based on a related column between them. SQL Join types are


as follows:
1) 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.column2_name
FROM table_name1,table_name2
where
table_name1.column_name=table_name2.column_nam
e;
Example:
Select stud_info.stud_name, stud_info.branch_code,
branch_details.location
From stud_info, branch_details
Where
Stud_info.branch_code=branch_details.branch_code;
2) SELF JOIN:
The SQL SELF JOIN is used to join a table to itself, as if the table
were two tables, temporarily renaming at least one table in the SQL
statement.
Syntax:
SELECT a.column_name, b.column_name
FROM table1 a, table1 b
WHERE a.common_filed = b.common_field;
Example:
Select x.stud_name, y.stud_name
from stud_info x, stud_info y
Where x.leader= y.stud_id;

3) 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.
Syntax:
Select column1_name,column2_name
from table1name any_alias1 ,table2name any_alias2
on any_alias1.columnname(+) =

Page 13 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

any_alias2.columnname;
OR
Select column1_name,column2_name
from table1name left outer join table2name
on table1name.columnname= table2name.columnname;
Example:
select last_name, department_name
from employees e, departments d
on e.department_id(+) = d.department_id;
OR
select last_name, department_name
from employees left outer join departments
on employees.department_id =
departments.department_id;

4) 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, table2name any_alias2
on any_alias1.columnname =any_alias2.columnname
(+);
OR
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,
departments d on
e.department_id = d.department_id(+);
OR
Select last_name, department_name
from employees e right outer join departments d
on e.department_id = d.department_id;
5) NON EQUI JOIN:
Non equi joins is used to return result from two or more tables

Page 14 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

where exact join is


not possible.
Syntax:
Select aliasname.column1name,
aliasname.column2name from tablename alias
where <condition using range>;
Example:
In emp table and salgrade table. The salgrade table contains
grade and their low salary and high salary. Suppose you want
to find the grade of employees based on their salaries then
you can use NON EQUI join.
Select e.empno, e.ename, e.sal, s.grade
from emp e, salgrade s
where e.sal between s.lowsal and s.hisal;
d) Draw ER diagram for hospital management system 4M
Ans. Note: Any other relevant example shall be considered
Correct
use of
symbols
2M

Correct
Entities 1M

Correct
relation
ships
1M

Page 15 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

e) Explain database recovery techniques with example. 4M


Ans. Note Any other relevant example shall be considered. Descriptive
example shall be considered Any 2
techniques
Database Recovery Techniques: Database recovery techniques are
1½ M each
used to restore the original data in system from backup. Backward
and forward recovery is two types of database recovery. Example
Recovery Techniques: 1M
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.

Example :Consider multiple transactions named t1,t2,t3, and t4 as


shown in the image below. A checkpoint at a time during the first
transaction and the system fails during the fourth transaction, but it is
possible to recover the data to the state of the checkpoint made during
t1.
A checkpoint is made after all the records of a transaction are written
to logs to transfer all the logs from the local storage to the permanent
storage for future use.

Page 16 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

(OR)

5. Attempt any TWO of the following: 12


a) i) Write a query to create table emp-details (Emp_ID, name, 6M
dept) with proper data types and Emp_ID as primary key and Correct table
name as NOT NULL constrain. creation query
1M,
ii) Perform all DML command on above created table.
applying
Ans. i) Write a query to create table emp-details (Emp_ID, name, Primary key
dept) with proper data types and Emp_ID as primary key and and Not null
name as NOT NULL constrain. constraint 1M
each
Create table emp_details(Emp_IDnumber(4) Primary key,
Name varchar2(10) not null, Consider any
Dept varchar2(10)); correct query
for INSERT,
OR UPDATE and
DELETE
Create table emp_details (Emp_IDnumber(4) constraint PK Primary 1M each
key,
Name varchar2(10) constraint NN not null,
Dept varchar2(10));

ii) Perform all DML command on above created table.


Insert into emp_details
Values(1111, „Rajan‟, „Computer‟);

Page 17 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

Select * from emp_details where emp_id=1111 ;

Update emp_details
Set name= „Rajani‟
Where emp_ID=1111;

Delete from emp_details


Where emp_id=1111;

b) Create simple and composite index. Write command to drop 6M


index.
Ans. Note: Any other relevant syntax or example shall be considered Simple index
Create simple index 2M
Syntax: Create index index_name on <tablename>(<column name>); Composite
(OR) index 2M
Example: Create index idx_empno on employee (empno);
Drop index
Create composite index: 2M
Syntax: Create index index_name on
<tablename>(<Column_name1,Column_name2>);
(OR)
Example: Create index idx_ename_eno on employee (ename,
empno);

Drop Index:
Syntax: Drop index <index_name>;
(OR)
Example:(Assuming idx_empno created on employee table)
Drop index idx_empno;

c) Differentiate between PL/SQL procedure and function with 6M


syntax and example.
Ans. Based on Function Procedure Any six points
including
Basic It calculates the result It performs certain syntax and
based on given inputs. tasks in order. example 1M
SQL Query It can be called in a It cannot be called in a each
query. query.

Page 18 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

SELECT There can be a There is no procedure


function call in a call in a SELECT
SELECT statement. statement.
Return It returns the resultingOn the other hand, it
value or control to the returns control but does
calling function or not return a value to the
code. code or calling
function.
DML DML statements such In a procedure, DML
statements as (Insert, statements can be used.
Delete, and Update) c
annot be used in a
function.
Call We can call a function Whereas it is not
via the procedure. possible to call a
procedure via function.
Expression It has to deal with an It does not have to deal
expression. with an expression.
Compilation Functions are Procedures need to be
compiled whenever compiled once, and if
they are called. necessary, we can call
them repeatedly
without compiling
them every time.
Explicit There is no explicit It can use explicit
transaction transaction handling in transaction handling.
a function.
Syntax CREATE [OR CREATE or
REPLACE] REPLACE
FUNCTION PROCEDURE
function_name name(parameters)
[(parameter_name
type [, …])] IS
RETURN variables;
return_datatype BEGIN
{IS | AS} //statements;
BEGIN END;
// program code
[EXCEPTION

Page 19 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

exception_section;]
END
[function_name];
Example create or replace CREATE OR
function circle_area(r REPLACE
number) PROCEDURE
return number greetings
is AS
area number; BEGIN
pi constant dbms_output.put_line('
number(3,2):=3.14; Hello World!');
begin END;
area := pi*r*r; /
return area;
end circle_area;

6. Attempt any TWO of the following: 12


a) Explain use of database trigger. List types of trigger. Write 6M
command to create and delete trigger.
Ans. Use of trigger Use 2M
Trigger: A trigger is a stored procedure in database which
List of types
automatically invokes whenever a special event in the database 1M
occurs. A trigger can be invoked when a row is inserted into a
specified table or when certain
table columns are being updated. Triggers are written to be executed
in response to any of the following
Command for
events − create 2M
A database manipulation (DML) statement (DELETE, INSERT, or
UPDATE)
Database definition (DDL) statements (CREATE, ALTER, or Command for
DROP). delete 1M
A database operation (SERVERERROR, LOGON, LOGOFF,
STARTUP, or SHUTDOWN).
Triggers can be defined on the table, view, schema, or database with
which the event is associated.
Triggers can be written for the following purposes –
 Generating some derived column values automatically
 Enforcing referential integrity

Page 20 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

 Event logging and storing information on table access


 Auditing
 Synchronous replication of tables
 Imposing security authorizations
 Preventing invalid transactions
Types of trigger
 DML Triggers
 DDL Triggers
 Logon Triggers

Example: To create Trigger:


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 + Student.subj3,
Student.per= Student.total * 60 / 100;

To delete a trigger:
DROP TRIGGER stud_marks;

b) Consider following schema” 6M


Book-master (bookid, bookname, author, no_of_copies, price)
write down SQL queries for following:
i) Write a command to create Book_master table.
ii) Increase the price of all books by 20%
iii) Display all books whose price ranges from 500 to 800.
iv) Display all books with details whose name start with ‘D’
v) Dsipaly all books whose number of copies are less than 10.
vi) Display all books whose price is above 700.

Page 21 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

Ans. (i)Write a command to create Book_Master table table. Each correct


SQL>Create table Book-Master( query 1M
bookidnumber(5),
booknamevarchar2(10),
authorvarchar2(20),
no_of_copiesnumber(10),
price number(10,2)
);

(ii) Increase the price of all books by 20%.


SQL>Update book_master
Set price=price+(price*0.2);

(iii)Display all books whose price is between Rs.500 & Rs. 800
SQL> Select * from Book_Master where price between 500 and800;
OR
SQL> Select * from Book_Master where price >=500
andprice<=800;

(iv) Display all books with details whose name start with ‘D’
SQL> Select bookname from Book_Master where bookname like
„D%‟;

(v)Display all books whose number of copies are less than 10


SQL>Select * from Book_Master where no_of_copies<10;

(vi) Display all books whose price is above Rs. 700


SQL>Select * from Book_Master where price >700;
c) Write SQL command for following: 6M
i) Create user
ii) Grant privileges to user
iii) Remove privileges from user
Ans. Note: Any other relevant syntax or example shall be considered Each correct
i) Create user command 2M
CREATE USER <username> IDENTIFIED BY <password>;
(OR)
CREATE USER RAJ IDENTIFIED BY RAJ123;

Page 22 / 23
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER – 2024 EXAMINATION


MODEL ANSWER
Subject: Database Management System Subject Code: 22319

ii) Grant privileges to user.


GRANT <privilege list> ON <relation name or view name>
TO<user list>;
(OR)
(assuming table Employee for granting permissions to user
„RAJ‟
for select, insert, update and delete privilege)
GRANT SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE TO RAJ;

iii) Remove privileges from user.


REVOKE <privilege list> ON <relation name or view name >
FROM <user list>;
(OR)
(assuming table Employee for revoking permissions to user
„RAJ)
REVOKE SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE FROM RAJ;

Page 23 / 23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy