DBMS Summer-19 (Answers)
DBMS Summer-19 (Answers)
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
SUMMER – 19 EXAMINATION
Subject Name: Database Management System Model Answer Subject Code: 22319
2. REVOKE
e Define Normalization and list its types. 2M
Ans Normalization is a process of organizing the data in database to avoid 1 M for
data redundancy, insertion anomaly, update anomaly & deletion definition, 1 M
anomaly. for the types
Example:
DELETE FROM Employees
WHERE Emp_id=100;
ROLLBACK command can be used to get deleted record.
TRUNCATE Command :
It is a DDL( Data Definition Language) command
It is used to remove all records permanently.
WHERE clause can be used as it removes all records.
Syntax:
TRUNCATE TABLE Table_name;
Example:
TRUNCATE TABLE Employees;
ROLLBACK command cannot be used to get records.
New records can be added into a table as structure remains
intact.
OR
DELETE TRUNCATE
It is DML(Data It is a DDL( Data
Manipulation Language) Definition Language)
command command
It is used to remove all or It is used to remove all
specific records of table. records permanently.
WHERE clause can be used WHERE clause can be
to remove specific records. used as it removes all
records.
2. Complex view: The fields in a view are fields from more than one
table in the database. You can add SQL functions, WHERE, and JOIN
statements to a view and present the data as if the data were coming
from different table.
Example
Create view mumbai_customers AS
Select customer_name,contact_name
From customers
Where city=’Mumbai’;
Declaration section
Execution section
Exception section
It is used to handles the exceptions. It is an Optional block.
End statement
It is used to indicate termination of PL/SQL block. It is mandatory.
111 Math’s 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40
CandidateKeys:{teacher_id,subject}
teacher_id teacher_age
111 38
222 40
333 40
teacher_subject Table:
Teacher_id Subject
111 Math’s
111 Physics
222 Biology
333 Physics
333 Chemistry
User-defined exceptions
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
……
….….
END;
Raising Exceptions
DECLARE
exception_name EXCEPTION; BEGIN
IF condition THEN
RAISE exception_name;
END IF;
EXCEPTION
WHEN exception_name THEN
statement;
END;
You can use the above syntax in raising the Oracle standard exception
or any user-defined exception.
Example :
DECLARE
A number:=20;
B number:=0;
C number;
BEGIN
dbms_output.put_line(‘First Num : ’||A);
dbms_output.put_line(‘Second Num : ’||B);
C:= A / B;
--Raise built in Exception if B is 0
dbms_output.put_line(‘ Result ’ || C);-- and then Result will not
be displayed
EXCEPTION
WHEN ZERO_DIVIDE THEN
dbms_output.put_line(‘ Trying to Divide by zero :: Error ’);
END;
Active –the initial state; the transaction stays in this state while it is
executing
Partially committed –after the final statement has been executed.
Failed - after the discovery that normal execution can no longer
proceed.
Aborted – after the transaction has been rolled back and the database
restored to its state prior to the start of the transaction. Two options after
it has been aborted: restart the transaction - can be done only if no
internal logical error kill the transaction Committed –after successful
completion.
Example : Example :
Like operator :
The LIKE operator is used to compare a value to similar values using
wildcard operators. It uses two wild characters as ‘%’ and ‘_’ where ‘%’
represents all characters of the pattern and ‘_’ represents one single
character from pattern.
Eg :
Select ename from emp where ename like ‘S%’;
This will return all employee names starting with ‘S’.
Select ename from emp where ename like ‘_a%;
This will return all employee names whose second character is ‘a’.
Ans A cursor is a temporary work area created in system memory when a Explanation :
SQL statement is executed. A cursor is a set of rows together with a 2M, example :
pointer that identifies a current row. It is a database object to retrieve 2M
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.
Each cursor contains the followings 4 steps,
Declare
enumemp.eno%type;
enemp.ename%type;
Cursor cur is select eno, ename from emp where jobname = “mgr”;
Begin
Open cur;
Loop Fetch cur into enum,en;
Exit when cur%NOTFOUND;
Dbms_output.put_line(„emp num ‟||enum||‟ emp name „||en);
End loop;
Close cur;
End; /
The example shows fetching multiple records using cursor. 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.
In the example, the cursor is defined to hold the rows as defined by the
select query. Once the cursor is defined, the next step is to open the
cursor. When the cursor is opened, it is ready to retrieve the rows. This
is done using the fetch statement. Since there are many rows, a loop is
used to display the values of all the rows. Once the rows are fetched, the
cursor should be closed.
d State the use of database trigger and also list types of trigger. 4M
DML Triggers
DDL Triggers
Logon Triggers
After roll forward, the data blocks contain all committed changes as
well as any uncommitted changes that were recorded in the redo log.
Ans Correct
entities: 2M,
correct
symbols: 2M,
Correct
relationships:
2M
(OR)
Drop sequence:
dbms_output.put_line('Factorial='||fact);
END; /
(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;
(OR)
(assuming table Employee for revoking permissions to user ‘RAJ)
REVOKE SELECT, INSERT,UPDATE,DELETE ON
EMPLOYEE FROM RAJ;