Sie sind auf Seite 1von 18

JSPM’s

JAYAWANTRAO SAWANT POLYTECHNIC,


Handewadi Road, Hadapsar, Pune-28
Department of Information Technology
Academic Year 2019-20
ASSIGNMENT-I MODEL ANSWER
(For Class -‘A’ Students)

Subject: Database Management Subject Code: 22416


Course & Code: IF4I Class: SYIF
Semester: FOURTH Name of the Faculty: Mrs.Jadhav D.S.
Date: 4/12/2019

CO 1: Create Database using SQL commands.

UNIT 1: Creating Relational Database (8 Marks)


Q. Model Answer Marking
No. Scheme
Explain DELETE and DROP Command with syntax and example. (DELETE
Command: 2
DELETE Command: marks
The SQL DELETE Query is used to delete the existing records from a ,DROP
table. You can use WHERE clause with DELETE query to delete selected command:
rows, otherwise all the records would be deleted. 2 marks)
Syntax:
DELETE FROM table_name WHERE [condition];
Example:
1) To Delete record from customer table with Name as JACK
1.
DELETE FROM CUSTOMER WHERE NAME = 'JACK';

DROP Command:
The SQL DROP Command is use to delete all records
and schema of the table.
Syntax:
DROP Table <table name>;
Example:
Drop table emp;

Give the syntax and example of CREATE and RENAME Commands. (Each
Command
The Syntax for the CREATE TABLE command is: Syntax with
CREATE TABLE <table_name> example: 2
2. (<column_name1>< datatype>(size), marks)
<column_name2>< datatype> (size),
.
.
<column_nameN>< datatype> (size));
For Example:
To create the employee table, the statement would be like,
CREATE TABLE employee
(emp_id number(5),
name char(20),
deptno number(2),
dob date,
salary number(10,2),
address varcharchar2(30) );

The Syntax for the RENAME TABLE command is:


RENAME <old_table_name> To < new_table_name>;
For Example:
To change the name of the table employee to my_employee, the query
would be like,
RENAME employee TO my_employee;

Explain ALTER command with any two options. (Explanation


:2 marks,
The SQL ALTER TABLE command is used to modify the definition any two
(structure) of a table by modifying the definition of its columns options:2
It can be used for marks)
1.To add any new column to a table
2. To change data type or size of already existing data column of a table.
3.To delete a column from a table
4.To add / drop constrains from column of a table.

The three options with ALTER command are:


1.Add column:-We can add any number of columns in a table using
ALTER table command with add clause. Added column becomes last
column by default.

Syntax to add a column:-


ALTER TABLE <table_name>
ADD (<column_name1>< datatype>(size),
.
3. .
<column_nameN>< datatype>(size) );

2.Drop Column: - We can delete the existing column with help of


drop clause in the ALTER table command. We can drop one column at a ti
me. After dropping any column from the table, there must be at least one
column left in the table.

Syntax to drop a column:-


ALTER TABLE <table_name >
DROP column <column_name>;

3.Modify column:-We can change the data type and/or size of a column
in a table by using modify clause in ALTER table. The size of the
column can be increased or decreased if the column contains only null
values or if the table has no rows.

Syntax to modify a column


ALTER TABLE <table_name >
MODIFY( <column_name1>< datatype>(size),
<column_name2>< datatype>(size),
.
.
<column_name N>< datatype>(size)) ;

Describe Relational model with example. (Explanation


-2 marks;
Relational Model: example -
Relational Model represents the database as a collection of tables. A table 2 marks)
is a database object that stores data in form of rows and columns. Each row
in the table represents collection of related data value.
Tuple: In relational model, a row is called as tuple.
Attribute: A column header is called as an attribute.
Degree: The degree of relation is number of attributes of the table.
Domain: All permissible values of attributes is called as a domain.
Cardinality: Number of rows in the table is called as cardinality
e.g.
Create table Student_details
(RollNo number(3),
4. Name varchar(15));

Student_details

In the above example Student_details is the name of Relation.


There are two attributes RollNo and Name so Degree is 2.
In the relation there are three tuples (rows) so Cardinality is 3.

Differentiate between DBMS and RDBMS. (Any 4 valid


differences
–1 Mark
each)

5.

Subject teacher HOD


JSPM’s
JAYAWANTRAO SAWANT POLYTECHNIC,
Handewadi Road, Hadapsar, Pune-28
Department of Information Technology
Academic Year 2019-20
ASSIGNMENT-II MODEL ANSWER
(For Class -‘A’ Students)

Subject: Database Management Subject Code: 22416


Course & Code: IF4I Class: SYIF
Semester: FOURTH Name of the Faculty: Mrs.Jadhav D.S.
Date: 4/12/2019

CO 2: Manage Database using SQL commands.

UNIT 2: Interactive SQL for Data Extraction (18 Marks)


Q. Model Answer Marking
Scheme
No.
Explain any four string functions with example. Explanation
:1 mark,
Example: 1
mark)

1.
Explain Inner join and Outer join with example. (Inner join
:Explanation
INNER Join: 1 mark,
This is a simple JOIN in which the result is based on matched data as per Example 1
the condition specified in the query. mark, Outer
join :
Inner Join Syntax : Explanation
SELECT column_name_list 1 mark,
from table_name1 Example 1
INNER JOIN mark)
table_name2
on table_name1.column_name = table_name2.column_name;

Inner Join Example :


SELECT * from emp inner join dept on emp.id = dept.id;
2. Outer Join is based on both matched and unmatched data. Outer Joins
subdivide further into,
•Left Outer Join
•Right Outer Join
•Full Outer Join

Left Outer Join


The left outer join returns a result table with the matched data
of two tables then remaining rows of the left table and null for the right
table's column.

Left Outer Join syntax :


SELECT column-name-list from
table-name
LEFT OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;
Left Outer Join Example:
SELECT * FROM emp LEFT OUTER JOIN dept ON (emp.id=d
ept.id);

Right Outer Join


The right outer join returns a result table with the matched data
of two tables then remaining rows of the right table and null for the left
table's columns.

Right Outer Join Syntax:


select column-name-list from
table-name1
RIGHT OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;

Right Outer Join Example:


SELECT * FROM emp
RIGHT OUTER JOIN
dept on (emp.id=dept.id)

Full Outer Join


The full outer join returns a result table with the matched data
of two table then remaining rows of both left table and then the
right table.

Full Outer Join Syntax :


select column-name-list from
table-name1
FULL OUTER JOIN
table-name2
on table-name1.column-name = table-name2.column-name;

Full Outer Join Example:


select empname,sal
from emp
FULL OUTER JOIN
dept on emp.id = dept.id;

Explain the set operator with help of example. (Each


operator - 1
Set operators combine the results of two component Mark)
queries into a single result. Queries containing set operators are called as
compound queries. Set operators in SQL are represented with following
special keywords as: Union, Union all, intersection & minus.
Consider data from two tables emp1 and emp2 as
3. emp1 emp2
ename ename
abc pqr
xyz xyz
lmn

1)Union : The Union of 2 or more sets contains all elements


, which are present in either or both. Union works as or.
Eg select ename from emp1 union select ename from emp2;
The output considering above data is :
Ename
abc
xyz
lmn
pqr

2)Union all : The Union of 2 or more sets contains all elements, which are
present in both, including duplicates.
Eg select ename from emp1 union all select ename from emp2;

The output considering above data is :


Ename
abc
x yz
lmn
pqr
xyz

3)Intersect: The intersection of 2 sets includes elements which are present


in both.
Eg select ename from emp1 intersect select ename from emp2;

The output considering above data is:


Ename
xyz

4)Minus: The minus of 2 sets includes elements from set1 minus elements
of set2.
Eg select ename from emp1 minus select ename from emp2;

The output considering above data is:


Ename
a bc
lmn

Explain any four date function with example. (Any four


functions -1
1)Month_between(d1,d2) Mark Each)
where d1 and d2 are dates.
Months_between finds the number of months between d
1 and d2. If date d1 is later than d2 the result is positive. If date d1 is
earlier than d2 the result is negative.
Example:
Select months_between (‘05-MAY-1996’, ‘05-JAN-199
4. 6’) from dual;

2)add_months(d,n)
where d-date, n-number of months to be added to the date
Return date after adding the number of months specified with the function.
Example:
Select add_months(hiredate,2) from emp where empno
=7369;
3)next_day(d,char)
where d-date, char-day of week.
Return the date of the first weekday named ‘char’ that is later than date ‘d’.
Example:
Select next_day(‘01-FEB-2006’, ‘Wednesday’) “nex
t_day” from dual;

4)Last_day(d)
Where d-date
Return the last day of the month that contain date ‘d’. Used to determine
how many days left in a month.
Example:
Select last_day(sysdate) “last” from dual;

5)round(date,[fmt])
where ‘fmt’-format model: Month,Day.Year
Return date rounded to the unit specified by the format model ‘fmt’. If the
format model ’fmt’ is omitted, date is rounded to the nearest date.
Example:
Select round(sysdate, ‘day’) “round_day” from dual;

6)trunc(date,[fmt])
where ‘fmt’-format model: Month, Day, Year
Return date with the time portion of the day truncated to the unit specified
by the format model fmt. If the format model fmt is omitted, date is
truncated to the nearest day.
Example:
Select trunc(sysdate, ‘day’) “trunc_day” from dual;

How to use COMMIT, SAVE POINT, ROLLBACK commands. ( Explanation


–3Marks
Commit: , Example
The COMMIT command is used to save changes invoked by a transaction –1Mark)
to the database.
The COMMIT command saves all transactions to the
database since the last COMMIT or ROLLBACK command.
The syntax for COMMIT command is as follows:
SQL> COMMIT;

Savepoint:
A SAVEPOINT is a point in a transaction when you can roll the
5. transaction back to a certain point without rolling back the entire
transaction.
The syntax for SAVEPOINT command is as follows:
SAVEPOINT SAVEPOINT_NAME;
e.g.
SAVEPOINT SV1;

Rollback:
The ROLLBACK command is used to undo transactions that have not
already been saved to the database.
The ROLLBACK command can only be used
to undo transactions since the last COMMIT or ROLLBACK command
was issued.
The syntax for rolling back to a SAVEPOINT is as follows:ROLLBACK
TO SAVEPOINT_NAME;
e.g.
ROLLBACK TO sv1;

Subject teacher HOD


JSPM’s
JAYAWANTRAO SAWANT POLYTECHNIC,
Handewadi Road, Hadapsar, Pune-28
Department of Information Technology
Academic Year 2019-20
ASSIGNMENT-III MODEL ANSWER
(For Class -‘A’ Students)

Subject: Database Management Subject Code: 22416


Course & Code: IF4I Class: SYIF
Semester: FOURTH Name of the Faculty: Mrs.Jadhav D.S.
Date: 4/12/2019

CO 3: Implement advanced SQL concepts on database.

UNIT 3: Advance features of SQL (16 Marks)


Q. Model Answer Marking
Scheme
No.

What are sequences? Why it is used? Create sequence for STUDENT (Definition
table. -1 mark;
Use -1 mark;
Definition: creating valid
A sequence refers to a database object that is capable of generating unique sequence
and sequential integer values. example/
Use: pattern
1. 1.It saves a time by reducing application code. -2 marks)
2.It is used to generate unique sequential integers.
3.It is used to create an auto number fields.
4.Sequence can be use for many tables/relations

Sequence for ‘student’ table:


Create sequence student_seq increment by 1 start with 1 maxvalue
60 nocycle;

What are synonyms? How to create and drop synonym? (Definition


-1 Mark
Synonyms: , Syntax
Synonym is another name given to the table, view, sequence, stored /Example
procedure, function or packages for the user‟s convenience to use it. -1 ½ Marks)
2.
Creating Synonyms:
Create synonym <synonym name> for <object name>;
Create synonym employee1 for employee;
Dropping Synonyms:
Drop synonym <synonym name>;
Drop synonym employee1;

Consider following schema. (Correct


Employee (empname, empid, dob, salary, job) query: 4
Create a view on employee having attribute (empname, empid, dob, marks)
salary, job) where salary is greater than 20,000.

Create view EMPVIEW as select empname, empid, dob, salary, job from
3. employee where salary>20000;

OR

CREATE VIEW EMPVIEW AS SELECT * FROM EMPLOYEE


WHERE SALARY > 20000;

Explain views with example. (Explanation


of view with
Views are created for security reasons. Instead of coping same table syntax – 3
multiple times for different requirements, views can be created. View is a Marks,
logical copy of physical table. It doesn’t exist physically. With the help of Example
view, we can give restricted access to users. When view is used,underlying - 1 Mark)
table is invisible, thus increasing security. Views can be used to see, insert,
update and delete data from base table.

Syntax for creating view:-


Create [OR Replace][Force /Noforce] view <viewname>[alias name ....]
As subquery
4. [with CHECK OPTION[CONSTRAINT]]
[with READ ONLY];

Example :
Create view emp_info as select Emp_no, Emp_name from Employee
where salary>12000;

To describe content of view


Select * from emp_info;

To describe structure of view


describe emp_info;

Explain the concept of indexing with neat diagram. (Explanation -


3 Marks, Any
Index: relevant
An index is a schema object that can speed up the retrieval of rows by Diagram - 1
using pointer. An index provides direct and fast access to rows in a table. Ma
Indexes are created explicitly Or automatically. Indexes are used to speed rk)
5. up searches/queries.

Types of Index:
Simple index(Single column):
An index created on single column of a table is called a Simple Index.
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.
Composite (concatenated):
Indexes that contain two or more columns from the same table which are
useful for enforcing uniqueness in a table column where there’s no single
column that can uniquely identify a row.

Subject teacher HOD


JSPM’s
JAYAWANTRAO SAWANT POLYTECHNIC,
Handewadi Road, Hadapsar, Pune-28
Department of Information Technology
Academic Year 2019-20
ASSIGNMENT-IV MODEL ANSWER
(For Class -‘A’ Students)

Subject: Database Management Subject Code: 22416


Course & Code: IF4I Class: SYIF
Semester: FOURTH Name of the Faculty: Mrs.Jadhav D.S.
Date: 4/12/2019

CO 4: Write PL/SQL code for database applications..

UNIT 4: PL/SQL Programming (16 Marks)


Q. Model Answer Marking
Scheme
No.

How to create trigger? State any two advantages of trigger. (Trigger


Syntax or
The Syntax for creating a trigger is: example
-2Marks, Any
CREATE [OR REPLACE ] TRIGGER trigger_name 2 advantages
{BEFORE | AFTER | INSTEAD OF } -2 Marks)
{INSERT [OR] | UPDATE [OR] | DELETE}
ON table_name
[FOR EACH ROW/For Each statement]
WHEN (condition)
BEGIN
---
sql statements
1. END;

(OR)

Example
CREATE or REPLACE TRIGGER After_Update_Row_product
AFTER
insert On product
FOR EACH ROW
BEGIN
INSERT INTO product_check Values('After update, Row level',sysdate);
END;
Advantages of triggers:
1.Triggers provide an alternative way to check the integrity of data.
2.Can catch errors in business logic in the database layer.
3.SQL triggers provide an alternative way to run scheduled tasks.
4.Triggers are very useful to audit the changes of data in tables.

Write a PL/SQL program which handles divide by zero exception. (Correct


Program
DECLARE -4 Marks)
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;
2. --
Raise Exception
dbms_output.put_line(„ Result ‟ || C);
--
Result will not be displayed
EXCEPTION
WHEN ZERO_DIVIDE THEN
dbms_output.
put_line(„ Trying to Divide by zero :: Error ‟);
END;
/

Differentiate between function and procedure. (Any four


point
–1Mark each
)

3.

What are Predefined exceptions and User defined exceptions? (Predefined


exception
1)Predefined Exception/system defined exception/named exception: -2 marks;
4. Are always automatically raised whenever related error occurs. The most User Defined
common errors that can occurs during the execution of PL/SQL. Not exception
declared explicitly. i.e. cursor already open, invalid cursor, no data found, -2 marks)
zero divide and too many rows etc.Programs are handled by
system defined Exceptions.
2)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 (error_no, error_name);
Write a PL/SQL program to find the square of a number given by (Correct
user using WHILE....LOOP.(accept the number from user Program
dynamically) -4 marks)

SET SERVEROUTPUT ON;


DECLARE
n number:= &n;
sqr number:= 0;
n_cntr number:=0;
5. BEGIN
DBMS_OUTPUT.PUT_LINE(n);
WHILE n_cntr< n
LOOP
sqr:= sqr + n;
n_cntr := n_cntr + 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Square of ' || n ||' is ' || sqr);
END;

Subject teacher HOD


JSPM’s
JAYAWANTRAO SAWANT POLYTECHNIC,
Handewadi Road, Hadapsar, Pune-28
Department of Information Technology
Academic Year 2019-20
ASSIGNMENT-V MODEL ANSWER
(For Class -‘A’ Students)

Subject: Database Management Subject Code: 22416


Course & Code: IF4I Class: SYIF
Semester: FOURTH Name of the Faculty: Mrs.Jadhav D.S.
Date: 4/12/2019

CO 5: Apply security and safety on database.

UNIT 5: Database Security and Transaction Processing (12 Marks)


Q. Model Answer Marking
Scheme
No.
Explain Lock Compatibility Table. What is Two-phase locking (Lock
protocol? compatibility
The two commonly used locks are 1) shared and 2) Exclusive table
1)Shared lock : It can lock the transaction only for reading. –
2)Exclusive Lock : It can lock the transaction for reading as well as 2 M
writing. arks
The compatibility table for these two locks can be given as: , two phase
locking
protocol

2M
arks
1. )

Two phase locking protocol:


This protocol is for ensuring serializability.
It requires the locking and unlocking of the transaction to be done in two
phases.
1)Growing phase:
In this phase, a transaction may obtain locks, but may not release locks.
2)Shrinking phase:
In this phase, a transaction may release locks, but may not acquire any new
locks.

2. What is schedule? Explain conflict serializability. (Schedule



Schedule : A Schedule is a nothing but the order in which multiple 1 M
transactions can be executed. ark
, Conflict
Conflict serializibility: serializibility
The correctness and consistency of transaction schedules can be decided by with suitable
serializibility property. The seriazable schedule is that which maintains the example
same consistency before and after the execution of a particular schedule. If –
it doesn‟t , it is called as conflict serializibility. Serial schedule never 3M
shows conflict serializibility, concurrent may show it. arks
)
Example :
Consider Transaction T1 : which transfers 50 Rs. From A‟ s account to
B‟s account.And transaction T2 : Displays (A+B) Initially a has 100 Rs
and B has 150 Rs. in their accounts respectively.The consistency can be
checked as after both the transactions are over (A+B) always should be
250. If not, there is a conflict serializibily

What is lock? Explain types of locks. (Lock


-2 marks;
The lock table statement allows explicitly acquire a shared or exclusive Description
table lock on the specified table. The table lock lasts until the end of the -1 mark each
current transaction. To lock a table, one must either be the database owner type)
or the table owner.

Syntax:
LOCK TABLE
TABLE-NAME
3. IN {SHARED | EXCLUSIVE} MODE;

Types of Locks:
Shared Lock
Exclusive Lock.

1.Shared. If a transaction Ti has obtained a shared-mode lock (denoted by


S) on item Q, then Ti can read, but cannot write, Q. Shared Lock is
provided to the readers of the data. These locks enable all the users to read
the concurrent data at the same time, but they are not allowed to change/
write the data or obtain exclusive lock on the object. It could be set for
Table or table row. Lock is released or unlocked at the end of transaction.
2.Exclusive. If a transaction Ti has obtained an exclusive-mode lock
(denoted by X) on item Q, then Ti can both read and write Q.Exclusive
Lock is provided to the writers of the data. When this lock is set on a
object or transaction, it means that only writer, who has set the lock can
change the data, and if other users cannot access the locked object. Lock is
released at the end of change in transaction.

Explain implicit and explicit locking strategies. (For each


locking
Implicit locks are generally placed by the DBMS automatically. Most strategies
DBMS allow the developer or the application to issue locks which are -2 Marks)
referred to as explicit locks.The default locking is done by the oracle server
4. implicitly by creating deadlock situation when the transaction is done on
the same database object(table) in different sessions. It is also called as
implicit locking or automatic locking. This lock held till the transaction is
completed.
Explicit locking are placed by application program.When locking is done
by the user with the help of SQL statement, it is called as explicit locking.

What is the use of GRANT and REVOKE? (GRANT


-2 Marks
Grant: , REVOKE
This command is used to give permission to user to do operations on the -2Marks)
other user‟s object.
Syntax: Grant
<object privileges>
on
<object name>
to
<username>[with grant option] ;

Example:
Grant select,update on emp to user1;
5.
Revoke:
This command is used to withdraw the privileges that has been granted to a
user.

Syntax: Revoke
<object privileges>
on
<object name>
from
<username> ;

Example:
Revoke select, update on empfrom user1;

Subject teacher HOD

Das könnte Ihnen auch gefallen