2019 Summer Model Answer Paper (Msbte Study Resources)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

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

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

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

answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant
ding.
7) For programming language papers, credit may be given to any other program based on
equivalent concept.

Q. Sub Answer Marking


No Q.N. Scheme
.
1. Attempt any FIVE of the following: 10
a) Enlist any four relational algebra operators. 2M
Ans. The fu
Any
i. Select
four
operator
iii. Union Operation ( )
s 1/2M
iv.
each
v.
vi.
b) State the u 2M
Ans.
The SQL BETWEEN clause allows user to easily test if an expression
is within a range of values (inclusive). The values can be text, date, or Any two
numbers. It can be used in a SELECT, INSERT, UPDATE, or uses 1M
DELETE statement. The SQL BETWEEN Condition will return the each
records where expression is within the range of value1 and value2
inclusive of the the values.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

c) 2M
difference).
Ans. Sr. GROUP BY HAVING
No.
1 The GROUP BY Clause HAVING Clause is utilized
is utilized in SQL with in SQL as a conditional
the SELECT statement to Clause with GROUP BY Any two
organize similar data into Clause. differen
groups. It combines the ces 1M
multiple records in single each
or more columns using
aggregate functions.
2 GROUP BY returns only This conditional clause
one result per group of data.returns rows where aggregate
function results match with
given conditions only.
d) State any two advantages of PL/SQL. 2M
Ans. Advantages of PL/SQL are:
SQL is the standard database language and PL/SQL is strongly
integrated with SQL. PL/SQL supports both static and dynamic
SQL. Static SQL supports DML operations and transaction
control from PL/SQL block. In Dynamic SQL, SQL allows Any two
embedding DDL statements in PL/SQL blocks. advanta
PL/SQL allows sending an entire block of statements to the ges 1M
database at one time. This reduces network traffic and provides each
high performance for the applications.
PL/SQL gives high productivity to programmers as it can query,
transform, and update data in a database.
PL/SQL saves time on design and debugging by strong features,
such as exception handling, encapsulation, data hiding, and
object-oriented data types.
Applications written in PL/SQL are fully portable.
PL/SQL provides high security level.
e) List any four statements of PL/SQL. 2M
Ans. PL/SQL has different categories of control statements. They are the
Any
following: four
statemen
1/2
Conditional selection statements: Includes IF statement and ts M
Case statement each
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

IF statement has these forms:


IF THEN
IF THEN ELSE
IF THEN ELSIF

Loop statements:
The loop statements are the basic LOOP, FOR LOOP,
and WHILE LOOP

Sequential control statements, : EXIT, CONTINUE and GOTO


Statements are Sequential Control Statements.

f) 2M
Ans. Oracle creates a memory area, known as the context area, for
processing an SQL statement, which contains all the information
needed for processing the statement; for example, the number of Definitio
rows processed, etc. n 2M
A cursor is a pointer to this context area. PL/SQL controls the
context area through a cursor. A cursor holds the rows (one or more)
returned by a SQL statement. The set of rows the cursor holds is
referred to as the active set.
g) Enlist the types of database users. 2M
Ans. Different Types of Database Users in DBMS:
1. Application Programmers
2. End Users
Casual User Each
Naive type 1/2M
Sophisticated users
Standalone users
3. DBA (Database Administrator)
4. System Analyst
2. Attempt any THREE of the following: 12
a) Describe simple and composite attribute with suitable example. 4M
Ans. Simple attribute
cannot be divided further. Each
For example, a student's phone number is an atomic value of 10 attribute
digits. with
Composite attribute example
one simple attribute. 2M
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

For example, a student's complete name may have first_name and


last_name.
b) Define the index with its characteristics. 4M
Ans. Definition
An index is a schema object. It is used by the oracle server to speed Definitio
up the retrieval of rows by using a pointer. n 2M

Characteristics of index:
1. It can reduce disk i/o by using a rapid path access to locate data Any two
quickly. characte
2. Indexes are logically and physically independent of the table they ristics
index. 1M each
3. These are maintained automatically by the oracle server.

c) Differentiate between PL/SQL function and procedure. (any four 4M


differences).
Ans.
Function Procedure
1.The function must return a 1. In Stored Procedure value
value return is optional. Even a
procedure can return zero or n
values.
2. Functions can have only input 2. Procedures can have input or Any
parameters for it output parameters. four
3. Functions can be called from 3. Procedures cannot be called differen
Procedure from a Function. ces 1M
each
4. Function allows only 4. The procedure allows
SELECT statement in it. SELECT as well as DML
(INSERT/UPDATE/DELETE)
statement in it.
5. Try-catch block cannot be 5. An exception can be handled
used in a Function. by try-catch block in a
Procedure

d) Describe database security with its requirements. 4M


Ans. Database security refers to the collective measures used to protect and
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

secure a database or database management software from illegitimate


use and malicious threats and attacks.
It is a broad term that includes a multitude of processes, tools and Descript
methodologies that ensure security within a database environment. ion 2M
Database security covers and enforces security on all aspects and
components of databases. This includes:
Data stored in database
Database server
Database management system (DBMS)
Other database workflow applications

Database Security Requirements:


The basic database security requirements which technology can
ensure are the following
1. Confidentiality: A secure system ensures the confidentiality of Require
data. This means that it allows individuals to see only the data they ments
are supposed to see. Confidentiality has several aspects like privacy 2M
of communications, secure storage of sensitive data, authenticated
users and authorization of users.
2. Integrity: A secure system ensures that the data it contains is valid.
Data is integrated means that data is protected from deletion and
corruption, both while it resides within the data-case, and while it is
being transmitted over the network.
3. Availability: A secure system makes data available to authorized
users, without delay. Denial of service attacks are attempts to block
authorized users' ability to access and use the system when needed.
3. Attempt any THREE of the following: 12
a) Give any four string functions with example. 4M
Ans. 1.initcap(str)
Converts first letter of string to capital letter. Any 4
Example: function
1M each

2. lower(str)
Converts a string to all lowercase characters.
Example:
dual;
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

3. upper(str)
Converts a string to all uppercase chracters.
Example:

4. length(str)
Find outs the length of given string.
Example:

5.ltrim(str)
Removesleading spaces from a string
Example:
Select l from dual;

6. rtrim(str)
Removes trailing spaces from a string
Example:
Select r abcd

7. Lpad(char1,length,char2)
It returns char1, left-padded to given length with the sequence of
characters in char2.
Example:
Select l

8. Rpad(char1,length,char2)
It returns char1, right-padded to given length
with the sequence of characters in char2.
Example:
Select r

9. Translate(char,from string, to string)


It returns expr with all occurrences of each character in from_string
replaced by its corresponding character in to_string
Example:

10. Replace(char,searchstring,[repstring])
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

It returns character string with each occurrences of searchstring


replaced with [repstring]
Example:

11. Substr(char,m,n)
It returns substring of character string that stack at m character and is
of length n
Example:
Select subs

12. Concat(str, str2)


It merges two or more strings or a string and a data value together
Example:
select concat('summer ','18') from dual;

13. Chr(n)
Returns a character binary equivalent of n.
select chr(65) from dual;

14. Ascii(char)
Returns a decimal representation of a character.

b) 4M
synonyms.
Ans. Create synonyms for class tables.
The following code shows how to create a synonym for the class 2M for
table creating
Example: synonym
Create Synonym Class.syn for class;
2M to
Write steps to create synonyms show the
Syntax: syntax
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .] of how
synonym_name to create
FOR [schema.] object_name; synonym
c) Write a PL/SQL program to display 10 reverse numbers. Use 4M

Ans.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

Declare 2M for
I number; correct
Begin syntax
For I in reverse 1..10
loop
Dbms_output.put_line(I); 2M for
End loop; correct
End; logic
d) Describe GRANT and Revoke with its syntax and example. 4M
Ans. Grant:
This command is used to give permission to user to do operations on Descript
the other user s object. ion of
Syntax: grant
Grant <object privileges>on< object name> to <username>[with 1M
grant option] ;
Example: Example
Grant select,update on emp to user1; 1M

Revoke:
This command is used to withdraw the privileges that has been Descript
granted to a user. ion of
revoke
Syntax: 1M
Revoke <object privileges>on<object name>
from <username> ; Example
Example: 1M
Revoke select, update on emp from user1;

4. Attempt any THREE of the following: 12


a) Consider following schema: 4M
Depositor (cust_name, acc_no)
Borrower (cust_name, loan_no)
Solve following queries:
(i) Find customer name having saving account as well as loan
account.
(ii) Fine customer names having loan account but not the savings
account.
Ans.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

i) Find customer name having saving account as well as


loan account:
Select d.Cust_name
From depositor d, borrower b Each
Where d. Cust_name=b.cust_name; query
2M
(ii) Find customer names having loan account but not the
savings account:
Select b.cust_name from borrower
minus
Select d.cust_name from depositor
Where d. Cust_name=b.cust_name;
(any other relevant logic can be cosidered for the query)
b) Create sequence for department table and also altered the 4M
created sequence.
Ans. 2M any
Create sequence deptid correct
Start with 1 syntax
Increment by 1 of
Maxvalue 100; create
sequenc
Alter the created sequence e
Alter sequence deptid maxvalue 1500; 2M for
altering
it
c) List the types of trigger. Write the steps to create trigger with 4M
example.
Ans. Types of Triggers:
1. Row-level trigger 2M for
2. Statement-level trigger listing
3. Before-trigger
4. After-trigger

Steps to create trigger: 2M for


1) Trigger can be created with the following syntax in database steps
environment : with
CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE | example
AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] |
DELETE} [OF col_name] ON table_name [REFERENCING OLD
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

AS o NEW AS n] [FOR EACH ROW] WHEN (condition)


2) User does not have to fire the trigger, but it gets automatically fired
according to definition of the trigger.
Example :
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
sal_diff number; BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' || :OLD.salary);
dbms_output.put_line('New salary: ' || :NEW.salary);
dbms_output.put_line('Salary difference: ' || sal_diff); END; /
d) Describe ACID properties of Transaction. 4M
Ans. A transaction is a single unit of execution. It can have different steps.
Every transaction in the DBMS must follow the ACID properties.
The ACID properties are:
A-Atomicity
C-Consistency
I-Isolation
D-Durability
Atomicity-
This property states that every transaction should be
treated as an atomic unit that is, either the entire transaction should be
completed totally or it should not be done at all. It also states that 1M for
under no condition should a transaction be partially completed. each
property
Consistency-
The database must remain in consistent state after any transaction.
The execution of a transaction should not result in inconsistency of
the database.

Isolation-
In systems where more than one transaction execute simultaneously
and in parallel, all transaction will be carried out and each transaction
should feel that it is the only transaction happening. If Ti,Tj are two
transactions, then Ti should feel that it is the only transaction
happening while it is executing, either Tj should have completed
execution or will execute once Ti completes.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

Durability-
The database should be durable enough to hold all its
latest updates even if the system fails or restarts. If a transaction
updates data in a database and commits, then the database will hold
the modified data. If a transaction commits but the system fails before
the data could be written on to the disk, then that data will be updated
once the system starts.
e) Define database backup. Describe how database backup helps to 4M
avoid failures.
Ans. Database backup:
Database Backup is storage of data that means the copy of the
data. 1M for
It is a safeguard against unexpected data loss and application definitio
errors. n
It protects the database against data loss.
If the original data is lost, then using the backup it can
reconstructed

The backups are divided into two types,


1. Physical Backup
2. Logical Backup

1. Physical backups 3M for


Physical Backups are the backups of the physical files used in explaini
storing and recovering your database, such as data files, control ng how
files and archived redo logs, log files. database
It is a copy of files storing database information to some other backup
location, such as disk, some offline storage like magnetic tape. helps to
Physical backups are the foundation of the recovery mechanism avoid
in the database. failures.
Physical backup provides the minute details about the transaction
and modification to the database.

2. Logical backup
Logical Backup contains logical data which is extracted from a
database.
It includes backup of logical data like views, procedures,
functions, tables, etc.
It is a useful supplement to physical backups in many
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

circumstances but not a sufficient protection against data loss


without physical backups, because logical backup provides only
structural information.

Describe how database backup helps to avoid failures.


You may think that your data files can be prevented from any kind of
loss by just replicating them to different locations in your disk which
is normally called backup. Well, Regular backups are essential in the
first place, but even they are subject to several failures that may
include the loss or breaking of hard disks and other non-volatile
storage devices.

In case, any kind of failure strikes your SQL server databases, a


proper plan and a way of recovery from that failure is needed,
beforehand. A good backup can indeed be the best way to recover
from most of the failures, especially when your data is too critical or
important.

In case, you lose a database or any of the table becomes corrupt, then
you can simply reload your data from the backup. In addition, if you
lose the whole server, then you may need to set up a new server and
re-install the SQL Server backup software, before using any of your
backups.

One of the most effective ways to prevent any kind of data loss and to
recover your original data in case of any failure is to store your entire
SQL server database off-site. A secure off-shore backup can save you
from many serious hassles in future.
5. Attempt any TWO of the following: 12
a) 6M
name, address, DOB and percent.

(iv) Remove/ delete the data or records from student info table.
Ans.

name, address, DOB and percent:


create table student
(
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

rollno number(5),
name char(20), Create
address varchar2(40), table 3M
DOB date,
percent number(5,2)
);

Add 1M
alter table student add (city char(20));
Change
the
rename student to student_info; name
1M
(iv) Remove/ delete the data or records from student info table:
truncate table student_info ; Remove/
(OR) delete
delete from student_info; data 1M
b) Describe Commit, Rollback and save point with example. 6M
(Note: Any other example shall be considered)
Ans. 1) Commit:
This command is used to end the transaction and also make its effect
permanent to database. Commit deletes or removes the save points if
any.
Syntax:
Each
commit; (OR) commit work;
descripti
2) Rollback on
A rollback command is used to undo the work done in current 1M
transaction.
Syntax:
Rollback;(or) Rollback work;

Syntax to rollback to a particular save point:


Rollback to savepoint<savepoint_name>;

Example: Rollback to save point SV1

3) Save point:
Save points define breakpoints for the transaction to have partial
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

rollback. Save points are treated as marker to divide lengthy


transaction to smaller one.

Syntax:
savepoint<savepoint_name>;

Example: Savepoint SV1;

Example showing usage of Commit, Rollback, Savepoint

SQL>CREATE TABLE emp (


no NUMBER(3),
name VARCHAR(50),
code VARCHAR(12)
);
SQL>SAVEPOINT table_create;
SQL>insert into emp VALUES(1,'RAM', 'E101');
SQL>SAVEPOINT insert_1;
SQL>insert into emp VALUES(2,'BEENA', 'E102');
SQL>SAVEPOINT insert_2;
Example
SQL>SELECT * FROM emp;
3M
NO NAME CODE
---------- ------------------------------------------ ------------
1 RAM E101
2 BEENA E102
SQL>ROLLBACK TO insert_1;
SQL>SELECT * FROM emp;

NO NAME CODE
---------- ------------------------------------------ ------------
1 RAM E101
SQL>COMMIT;
c) Give syntax for creating a view, Consider following schema- 6M
ACCOUNT (Account_No, Name, Account_Type, PAN_Number,
Balance). Create a view on ACCOUNT having attributes
(Account_No, Name, PAN_Number) where balance is less than
10,000.
Ans. Syntax for creating view:-
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

Create [OR Replace][Force /Noforce] view


Correct
as subquery Syntax
[with CHECK OPTION[CONSTRAINT]] 3M
[with READ ONLY];

Create view v1 as select Account_No, Name, PAN_Number from Correct


ACCOUNT where Balance<10000; Query
3M
6. Attempt any TWO of the following: 12
a) Consider the following data base scheme student (roll_no, name, 6M
city, marks, result). Write queries for the following:
(i) Display all students having result as first class.
(ii) Update roll_no of each student by adding 18 to it.
(iii) Delete percent column from table.

Ans. (i) Display all students having result as first class:

(ii) Update roll_no of each student by adding 18 to it:


update student set roll_no=roll_no+18; Each
correct
(iii) Delete percent column from table: Query
alter table student drop column percent; 1½M

b) Describe different types of Indexes with examples. 6M


Ans. Types of Index:
1) Simple index (Single column): An index created on single
column of a table is called a Simple Index.
Each
Syntax: Create index index_name on <tablename><column name>;
index
E.g.: Create index idx on employee (empno);
descripti
on 1M
2) Unique indexes are used not only for performance, but also for
data integrity. A unique index does not allow any duplicate values to
be inserted into the table.
Syntax :
Create unique index index_name on table_name(column_name);
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

E.g: Create unique index index_empno on emp(empno);

3) Composite (concatenated): Indexes that contain two or more


columns from the same table which are useful for enforcing Each
example
uniquely identify a row. 1M
Syntax: Create index index_name on <tablename><Column_name1,
Column_name2>;
E.g.: Create index idx on employee (ename, empno);
c) With suitable example write steps to create triggers and drop a 6M
trigger.
(Note: Any other example shall be considered)
Ans. Creating a trigger:
CREATE [OR REPLACE] TRIGGER trigger_name
BEFORE | AFTER
Trigger
[INSERT, UPDATE, DELETE [COLUMN NAME..] ON
creation
table_name 3M
Referencing [ OLD AS OLD | NEW AS NEW ]
FOR EACH ROW | FOR EACH STATEMENT [ WHEN
Condition ]
DECLARE
[declaration_section variable declarations; constant declarations; ]
BEGIN
[executable_section PL/SQL execute/subprogram body ]
EXCEPTION
[exception_section PL/SQL Exception block ]
END;
Keywords Description
Drop
CREATE [OR Creates the trigger. If already exist recreates
trigger
REPLACE] the trigger definition without requiring the 1M
user to drop the trigger first.
TRIGGERNAME Name of trigger to be created.
BEFORE Oracle engine fires the trigger before
executing triggering statement.
AFTER Oracle engine fires the trigger after
executing triggering statement.
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2005 Certified)

SUMMER 2019 EXAMINATION


MODEL ANSWER
Subject: Database Management Subject Code: 22416

DELETE Oracle engine fires the trigger whenever


delete statement removes a row from the
table.
INSERT Oracle engine fires the trigger whenever
insert statement add a row to the table.
ON Define the table name to performing trigger
TABLENAME event
REFERENCING Give referencing to a old and new values of
the data. :old means use existing row to
perform event and :new means use executing
new row to perform event.
Example:
Let's create a table 'product_check' which we can use to store Any
messages when triggers are fired. example
for
CREATE TABLE product_check trigger
(Message varchar2(50), creation
Current_Date date); 1M

BEFORE UPDATE, Statement Level: This trigger will insert a


record into the table 'product_check' before a sql update statement is
executed, at the statement level.
CREATE or REPLACE TRIGGER
Before_Update_Stat_product
BEFORE
UPDATE ON product
Begin
INSERT INTO product_check
Values('Before update, statement level',sysdate);
END;
/
Drop Trigger:
Drop trigger Trigger_name; Trigger
drop 1M
Example : Drop Trigger tr1;

You might also like