Database Management

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

DATABASE MANAGEMENT

Q.1

1. Define terms: i)Attribute ii) Domain 2M


Ans Domain: All permissible values of attributes are called as a domain.
Attribute: is a property or characteristics of an entity set.

2. State the use of ‘Like’ Operator. 2M


Ans The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two operator often used in conjunction with the LIKE operator:
%:The percent sign represents zero, one, or multiple characters
_: The underscore represents a single character.

3. Write syntax to create view. 2M


Ans Create view <view name> as select <query> OR
CREATE VIEW name ASSELECT column1, column2.....FROM table_nameWHERE
[condition];

4. List the types of Cursor.


Ans Cursor: A cursor is a temporary work area created in the system memory when a SQL
statement is executed.
Types of Cursor:
1.Implicit Cursor
2.Explicit Cursor

5. Enlist different types of database users. 2M


Ans Database users are the one who really use and take the benefits of database. There will be
different types of users depending on their need and way of accessing the database.
1. Application Programmers
2. Sophisticated Users
3. Specialized Users
4. Native Users/ Naïve Users

6. State the properties of Transaction. 2M


Ans The ACID properties of transaction.
1. Atomicity.
2. Consistency.
3. Isolation.
4. Durability

7. State the use of sequence. 2M


Ans A sequence refers to a database object that is capable of generating
unique and sequential integer values.
Syntax:
Create sequence<seq_name> [increment by num][start with num]
[maxvaluenum] [minvaluenum][cycle/no cycle][cache/no cache]
8. Enlist any four relational algebra operators.

9. State the use of ‘Between’ clause (any two user)


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 numbers. It can be used in a
SELECT, INSERT, UPDATE, or DELETE statement. The SQL BETWEEN Condition will
return the records where expression is within the range of value1 and value2 inclusive
of the the values

10. compare GROUP BY and HAVING

11. State any two advantages of PL/SQL.


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
embedding DDL statements in PL/SQL blocks. PL/SQL allows sending an entire block
of statements to the database at one time. This reduces network traffic and provides
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.
12. List any four statements of PL/SQL.
PL/SQL has different categories of control statements. They are the
following:
Conditional selection statements: Includes IF statement and
Case statement
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.

13. define the term ‘Cursor’


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 rows processed, etc.
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.

14. Enlist the types of database users.


Different Types of Database Users in DBMS:
1. Application Programmers
2. End Users
Casual User
Naive
Sophisticated users
Standalone users
3. DBA (Database Administrator)
4. System Analyst

Q.2
1. Describe the use of primary key and unique key constraints with
example?
4M
Ans There are two Entity constraints:
1.Primary Key constraint
2. Unique Constraint
1. Primary Key constraint: It is use to avoid redundant/duplicate value entry within the row of
specified column in table. It restricts null values too.
Syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME
DATA_TYPE, COLUMN_NAME DATA_TYPE CONSTRAINT
CONSTRAINT_NAME PRIMARY KEY);
Example: SQL> CREATE TABLE EMP (ID NUMBER
(5)CONSTRAINT ID_PK PRIMARY KEY, NAME VARCHAR2
(10), SAL NUMBER (10));
2. Unique Constraint: The UNIQUE constraint uniquely identifies each record in a database
table. The UNIQUE and PRIMARY KEY constraints both provide a guarantee for uniqueness
for a column or set of columns.
syntax: CREATE TABLE TABLE_NAME (COLUMN_NAME
DATA_TYPE, COLUMN_NAME DATA_TYPE CONSTRAINT
CONSTRAINT_NAME UNIQUE);
Example: CREATE TABLE PERSONS (P_ID NUM CONSTRAINT
P_UK UNIQUE , FIRSTNAME VARCHAR(20), CITY
VARCHAR(20) );

2. Write any two types of join with example of each

FULL JOIN: Full Join or the Full Outer Join returns all those records
which either have a match in the left (Table1) or the right (Table2) table.
For e.g.,
SELECT Employee.EmpFname, Employee.EmpLname, Projects.ProjectID
FROM Employee
FULL JOIN Projects
ON Employee.EmpID = Projects.EmpID;
LEFT JOIN: The LEFT JOIN or the LEFT OUTER JOIN returns all
the records from the left table and also those records which satisfy a
condition from the right table. Also, for the records having no matching
values in the right table, the output or the result-set will contain the
NULL values.
For e.g.
SELECT Employee.EmpFname, Employee.EmpLname,
Projects.ProjectID, Projects.ProjectName
FROM Employee
LEFT JOIN
ON Employee.EmpID = Projects.EmpID ;
RIGHT JOIN: The RIGHT JOIN or the RIGHT OUTER JOIN returns
all the records from the right table and also those records which satisfy
a condition from the left table. Also, for the records having no matching
values in the left table, the output or the result-set will contain the NULL
values.
For e.g.,
SELECT Employee.EmpFname, Employee.EmpLname,
Projects.ProjectID, Projects.ProjectName
FROM Employee
RIGHT JOIN: ON Employee.EmpID = Projects.EmpID;

3. Create Sequence seq-1 with starting value 1 and maximum value 20 with an increment of
1. Consider schema Customer (custno, custname, telephone) and use seq-1 for inserting a
row in customer table.Sequence:
It is database object that generate/produce integer values in sequential order.
It automatically generates primary key and unique key values.
It may be ascending or descending order
It can be used for multiple tables.
Sequence numbers are stored and generated independently of tables

For inserting the value using sequence


INSERT INTO Customer VALUES (SEQ-1.NEXTVAL, '1', 'George',1234567890);
4. Consider following schema product (prodid, prod name, rate, qty, manufacturer, qty-in-
stock). Write SQL queries for the following
i) Find total number of product manufactured by company “ABC”
ii) Display list of products with highest rated product coming at the top.
ANS: Find total number of product manufactured by company “ABC”
Select count(prodid) from product Where manufacturer=”ABC”;
Display list of products with highest rated product coming at the top
SELECT TOP 10 prodid, Product Name, rate
FROM Product ORDER BY rate DESC;

5. Describe simple and composite attribute with suitable example.


Simple attribute – simple attributes are atomic values, which cannot be divided further.
For example, a student's phone number is an atomic value of 10 digits.
Composite attribute – composite attributes are made of more than one simple attribute
For example, a student's complete name may have first_name and last_name.

6. Define the index with its characteristics.


Definition
An index is a schema object. It is used by the oracle server to speed
up the retrieval of rows by using a pointer.
Characteristics of index:
1. It can reduce disk i/o by using a rapid path access to locate data quickly.
2. Indexes are logically and physically independent of the table they index.
3. These are maintained automatically by the oracle server

7. Differentiate between PL/SQL function and procedure. (any four differences).

8. Describe database security with its requirements.


Database security refers to the collective measures used to protect and 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 methodologies that
ensure security within a database environment. 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
data. This means that it allows individuals to see only the data they
are supposed to see. Confidentiality has several aspects like privacy
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.

Q.3
1. Write a PL/SQL code to find sum of numbers from 1 to 20. 4M
Ans declare
i number(10);
ans number(10);
begin
ans:=0;
i:=1;
while i<=20 loop
ans:=ans+i;
i:=i+1;
end loop;
dbms_output.put_line('Sum of 1 to 20 numbers is:'||ans);
end;

2. Describe system and object privileges and also describe use of


Grant and Revoke commands with suitable example.
4M
Ans System Privileges: System privileges are privileges given to users to
allow them to perform certain functions that deal with managing the
database and the server.
e.g: Create user, Create table, Drop table etc.
Object Privileges:
Object privileges are privileges given to users as rights and restrictions
to change contents of database object – where database objects are
things like tables, stored procedures, indexes, etc.
Ex.Select, inserts, delete, update, execute, references etc.
Grant: This command is used to give permission to user to do
operations on the other user’s object.
Syntax: Grant <object privileges> on <object name> to
<username>[with grant option] ;
Example: Grant select, update on emp to user1;
Revoke: This command is used to withdraw the privilege that has been
granted to a user.
Syntax: Revoke <object privileges> on <object name> from
<username> ;
Example: Revoke select, update on emp from user1;

3. Describe concept of subqueries with example. 4M


Ans Subquery is a select statement that is embedded in a clause of another
SELECT statement i.e. nesting of queries or query within query.
Types of subqueries
1) Single row subqueries
2) Multiple row subqueries
3) Multiple column subqueries
Single row subqueries: A single row subquery is one that returns one
row from inner SELECT statement. This type of subquery uses single
row operators = , > , >= , < , <= , < >
Syntax:
SELECT column_name1… column_name n
FROM <table_name>
WHERE column1 operator (SELECT column from
<table_name> where condition);
Example :
Display the employee details whose job title is the same as that
of employee 1005.
Select empno,ename,job,salary,deptno
From emp
Where job=(select job from emp where empno=1005);
Multiple row subqueries: Subqueries that return more than one row are called multiple-row
subqueries. Multiple row operators are used instead of a subquery, with a multiple row subquery.

Syntax:
SELECT column_name1… column_name n
FROM <table_name>
WHERE column1 operator (SELECT column from <table_name>
where condition);
Example
Find the employees who earn the same salary as minimum salary for
departments.
Select empno,ename,job,salary,deptno
From emp
Where salary IN (select min(salary) from emp group by deptno);
Multiple column subqueries
Queries that return the values from more than one column are called
multiple column subqueries.
Syntax:
SELECT column_name1, ….. column_name n
FROM <table_name>
WHERE (column_name, column_name) IN
(SELECT column_name, column_name….from
<table_name> Where <condition> );
Example: Display the name, department number, salary and
commission of any employee whose salary and commission matches
both the commission and salary of any employee in department 10
Query: Select empno,deptno,salary,comm
From emp
Where (salary,comm) IN (select salary,comm from emp where
deptno=10);

4. Write syntax and example of create and drop synonym.


Ans Syntax:
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema.] synonym
name
FOR [schema.] object_name;
OR
create synonym name for object_name
Example:
Create synonym new_employee for employee
Syntax to drop synonym:
Drop synonym <synonym name>;
Example:
Drop synonym employee;
5. Give any four string functions with example.

6. create synonyms for ‘class’ tables. Write steps to create synonyms.


Create synonyms for class tables.
The following code shows how to create a synonym for the class
table
Example:
Create Synonym Class.syn for class;
Write steps to create synonyms
Syntax:
CREATE [OR REPLACE] [PUBLIC] SYNONYM [schema .]
synonym_name
FOR [schema.] object_name;

7. Write a PL/SQL program to display 10 reverse numbers. Use ‘for’ loop.


Declare
I number;
Begin
For I in reverse 1..10
loop
Dbms_output.put_line(I);
End loop;
End;
8. Describe GRANT and Revoke with its syntax and example.
Grant:
This command is used to give permission to user to do operations on
the other user s object.
Syntax:
Grant <object privileges>on< object name> to <username>[with
grant option] ;
Example:
Grant select,update on emp to user1;
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 emp from user1;

Q.4
1. Write steps to create execute and delete stored procedure. 4M
Ans Step 1:
Stored Procedure creation: A stored procedure has header, a declaration section, an executable
section and optional exception handling section.
Syntax:-
CREATE OR REPLACE PROCEDURE
<procedure_name>(<Argument> {IN | OUT | IN OUT}<Data
type>…){IS | AS}
Variable declarations;
Constant declarations;
BEGIN
<PROCEDURE_BODY>
EXCEPTION
Exception pl/sql block;
END ;
Step 2:
Executing Stored Procedure:
Use EXCE command with help of any application program
Ex:
EXEC use_test
Invoke this procedure from PL/SQL code block
DECLARE
BEGIN
use_test
END;
Step 3 : delete stored procedure
Syntax : drop procedure <procedure_name>; Ex: drop procedure use_test;
2. Describe simple and composite index.
1) Simple index (Single column): An index created on single column of a table is called a Simple
Index.
Syntax: Create index index_name on <tablename><column name>;
E.g.: Create index on employee (empno);
Composite (concatenated): Indexes that contain two or more columns from the same table
which are useful for enforcing uniquely identify a row.
Syntax: Create index index_name on <tablename><Column_name1,
Column_name2>;
E.g.: Create index on employee (ename, empno);

3. Consider the following schemas


Student(rollno, name, dt_of_birth,telephone)
Marks (rollno, sub1_marks, sub2_marks, per) Write SQL queries for the following.
i) Display student’s rollno, name, and marks of both subjects for all students.
ii)Delete all those students records who secured less than 35%
iii)Display all the students whose name start with ‘A’
iv)Update telephone number of student with rollno 101 as 9800010111
Ans i) Select Student.rollno, Student.name, marks.sub1_marks,
marks.sub2_marks from Student, marks where Student.rollno=marks.
Rollno;
ii)Delete from Student where rollno=(Select rollno from marks where
per<35);
iii) Select name from Student where name like ‘A%’;
(OR)
Select * from Student where name like ‘A%’;
iv) Update Student set telephone=9800010111 where rollno=101;

4. Describe types and causes of failure in database environment.


Types and causes of Failure in database environment:
1. Hardware Failure/System crash
There is a hardware malfunction that causes the loss of the content of volatile storage, and brings
transaction processing to a halt. The content of non-volatile storage remains intact, and is not
corrupted or changed.
2. Software Failure
The database software or the operating system may be corrupted or failed to work correctly, that
may causes the loss of the content of volatile storage, and results into database failure.
3. Media Failure
A disk block loses its content as a result of either a head crash or failure during a data-transfer
operation.
4. Network Failure
A problem with network interface card or network connection can cause network failure

5. Write a PL/SQL code to raise zero_divide exception, in case of division of a number by


another.
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 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;

6. Consider following schema:


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:
i) Find customer name having saving account as well as loan account:
Select d.Cust_name
From depositor d, borrower b
Where d. Cust_name=b.cust_name;
(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)

7. Create sequence for department table and also altered the created sequence.
Create sequence deptid
Start with 1
Increment by 1
Maxvalue 100;
Alter the created sequence
Alter sequence deptid maxvalue 1500;

8. List the types of trigger. Write the steps to create trigger with
example.
Types of Triggers:
1. Row-level trigger
2. Statement-level trigger
3. Before-trigger
4. After-trigger
Steps to create trigger:
1) Trigger can be created with the following syntax in database environment :
CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE |
AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] |
DELETE} [OF col_name] ON table_name [REFERENCING OLD
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; /

9. Describe ACID properties of Transaction.


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 under no condition should a transaction be partially completed.
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.
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
10. Define database backup. Describe how database backup helps to
avoid failures.
Database backup:
Database Backup is storage of data that means the copy of the
data.
It is a safeguard against unexpected data loss and application
errors.
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
Physical Backups are the backups of the physical files used in
storing and recovering your database, such as data files, control
files and archived redo logs, log files.
It is a copy of files storing database information to some other
location, such as disk, some offline storage like magnetic tape.
Physical backups are the foundation of the recovery mechanism
in the database.
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 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.

Q.5
1. Write SQL statements for following
i) Create table student with rollno, name, d-o-b, percentage, assign rollno as primary key.
ii) Add new column email in student table.
iii) Delete table ‘student’ with its structure and data.
Ans i) Create table student with rollno, name, d-o-b, percentage, assign
rollno as primary key.
Ans : Create table student( rollno number(5) primary key, name
varchar2(20), d-o-b date, percentage number(6,2)) ;
ii) Add new column email in student table.
Ans : Alter table student add email varchar2(30);
iii) Delete table ‘student’ with its structure and data.
Ans : Drop table student;

2. a) Consider following schema:


employee{empid,empname,designation,salary,deptno}
dept { deptno,deptname,location}
Write SQL queries for following :
i)Find maximum salary for deptno=10;
ii Increase salary of all employee by 5%
iii)Get the names of all ‘Manager’
iv) Display deptnames located at ‘Pune’ and ‘Nagpur’.
ANS:
i)Find maximum salary for deptno=10;
Ans:Select max(salary) from employee where deptno=10;
ii) Increase salary of all employee by 5%
Ans: Update employee set salary=salary+(salary*0.05);
iii) Get the names of all ‘Manager’.
Ans: Select empname from employee where designation=”Manager”;
iv) Display deptnames located at ‘Pune’ and ‘Nagpur’.
Ans: Select deptname from dept where location=’Pune’ or
location=’Nagpur’;

3. Write a PL/SQL code to create a function name square_no to


calculate square of number and also have another PL/SQL code to
call this function.
6M
Ans PL/SQL code for function to calculate square of a number:
create or replace function square_no(n in number)
return number is sqrno number;
begin
sqrno := n*n;
return(sqrno);
end;
PL/SQL code to call above function :
declare
n1 number;
sno number;
begin
n1 := &n1;
sno := square_no(n1);
dbms_output.put_line(“Number=”||n1);
dbms_output.put_line(“Square =;||sno);
end;

4.

5. Describe Commit, Rollback and save point with example.


(Note: Any other example shall be considered)
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:
commit; (OR) commit work;
2) Rollback
A rollback command is used to undo the work done in current 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 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;
SQL>SELECT * FROM emp;
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;

6. Give syntax for creating a view, Consider following schema- 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:-
Q.6
1. Consider schema ‘employee’ created by ‘user1’
Write SQL queries for following :
i) Grant ‘select’ and ‘insert’ permissions to user2.
ii) Assign all privileges for the user user3.
iii) Remove ‘select’ permission from user2 for table ‘employee’.
iv) Grant ‘update’ permission to user2 and user3
v) Remove all permission from user3.
vi) Assign ‘resource’ permission to user2.
Ans i) Grant ‘select’ and ‘insert’ permissions to user2.
Ans : grant select, insert on employee to user2;
ii) Assign all privileges for the user user3.
Ans : grant all on employee to user3;
iii) Remove ‘select’ permission from user2 for table ‘employee’.
Ans : revoke select on employee from user2;
iv) Grant ‘update’ permission to user2 and user3
Ans : grant update on employee to user2, user3;
v) Remove all permission from user3.
Ans : revoke all on employee from user3;
vi) Assign ‘resource’ permission to user2.
Ans : grant resource to user2;

2. Create a trigger which invokes on updation of record on emp table.


Ans create trigger trigger_update
on emp
after update
as
begin
Select * from employee;
end;
end;

3. Consider following schema:


Person {personid,name,address,city,telephone}
Write PL/SQL queries for following:
i) Create sequence seq-pid with start value 100 and maximum value 120 and increment by 1.
Use seq-pid to insert personid into table person.
ii) Create view view-person containing details of persons from city “Mumbai” and “Pune”
iii) Create synonym syn-person on table person owned by user ‘Scott’ delete synonym syn-
person.
Ans i) Create sequence seq-pid with start value 100 and maximum value 120
and increment by 1. Use seq-pid to insert personid into table person.
Ans: Create sequence seq_pid start with 100 increments by 1 maxvalue
120.
Insert into person (personid) values (seq_pid.nextval);
ii)Create view view-person containing details of persons from city
“Mumbai” and “Pune”
Ans: Create view person as select * from person where city=’Mumbai’
or city=’Pune’;
Or Create view view_peson as select * from persons where city in
(‘Mumbai’,’Pune’);
iii) Create synonym syn-person on table person owned by user ‘Scott’
delete synonym syn-person.
Ans: create synonym syn_person for scott.person;
Drop synonym syn_person;

4.

5. Describe different types of Indexes with examples.


Types of Index:
1) Simple index (Single column): An index created on single
column of a table is called a Simple Index.
Syntax: Create index index_name on <tablename><column name>;
E.g.: Create index idx on employee (empno);
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);

You might also like