DMS Practical Question

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

DMS Practical Exam Questions

1. Design ER Diagram and Normalize Database.

i.Draw ER Diagram for Railway Reservation System using minimum 4 entities.


(Hint: Customer Details,Train Detai1s,Payment Details etc)
ii. Normalize the database of Railway Reservation System upto 3NF.

2.Execute SQL Queries based on DDL Commands


i.Create table for stud using attributes Rollno, studname, percentage) apply primary key for
rollno and check constraint on percentage should not greater than 100.
ANS : CREATE TABLE STUD(ROLLNO INT PRIMARY KEY,STUDNAME VARCHAR(10),PERCENTAGE FLOAT);
ii.Change the stud table structure by adding column city .
ANS : ALTER TABLE STUD ADD CITY VARCHAR(20) ;
iii.Increase the size by 10 of studname column.
ANS : ALTER TABLE STUD MODIFY STUDNAME VARCHAR(30);

3.Execute DML Commands in SQL

Create a table EMPLOYEE with following schema:

Emp(Empno, Ename„ Deptno, Deptname,Job id, Salary,hiredate)

a.Insert at least 5 rows in the table.


ANS : INSERT INTO EMP VALUES(1,’XYZ’,20,’CO’,1108,35000,’3-NOV-2023’);

b. Display all the information of EMP table.


ANS : SELECT * FROM EMP;
c. Display the information of employees working in department PRODUCTION and salary
above 40000 .
ANS : SELECT * FROM EMP WHERE DEPARTMENT=’PRODUCTION’ AND SALARY>40000;
d. Update the salary of employees to 30000 working in department sales.
ANS : UPDATE EMP SET SALARY=30000 WHERE DAPARTMENT =’SALES’;
DMS Practical Exam Questions

e. Delete the employee working in SALES department having salary below 10000.
ANS : DELETE FROM EMP WHERE DEPARTMENT=’SALES’ AND SALARY<10000;

F .Display the complete record of employees working in SALES Department.


ANS : SELECT * FROM EMP WHERE DEPARTMENT= ‘SALES’;

4.Execute SQL Queries Using Arithmetic, Comparison, Logical, Set, Between and Like
Operators.

Consider the table EMPLOYEE and DEPARTMENT


Emp(Empno, Ename, Deptno, Deptname,Jobid, Salary,hiredate).

a.Display the name of employees who does not work under any Job id=2.
ANS : SELECT NAME FROM EMP WHERE JOBID NOT IN(2);

b. Display names of all employees whose name is exactly 6 characters long.


ANS : SELECT NAME FROM EMP WHERE LENGTH(ENAME)=6;
c. List all employees information except job id =2 and job id=3.
ANS : SELECT * FROM EMP WHERE JOBID NOT IN(2,3);

d. List the employee name and salary whose salary is not in the range of 20000 to 35000.
ANS : SELECT NAME,SALARY FROM EMP WHERE SALARY NOT BETWEEN 20000 AND 35000;

5.Execute SQL Queries Using String, Arithmetic,Date and Time, Aggregate Functions.

Consider the table EMPLOYEE and DEPARTMENT


Emp(Empno, Ename, Deptno, Deptname,Jobid, Salary,hiredate).

a.Display information of employees whose salary is greater than average salary of all
employees.
ANS : SELECT * FROM EMP WHERE SALARY>(SELECT AVG(SALARY) FROM SALARY);
DMS Practical Exam Questions

b. Display total employees in sales department.


ANS : SELECT COUNT(*) FROM EMP WHERE DEPARTMENT=’SALES ;
c. Display maximum and minimum salary of employees.
ANS : SELECT MIN(SALARY),MAX(SALARY) FROM EMP ;
d. Display total salaries of employees working in production department with Dept no
and location of department.
ANS : SELECT SUM(SALARY) FROM EMP WHERE DEPARTMENT=’PRODUCTION’ ;

6. Execute Queries Using the Select Command with where,Having, Group by and Order
by Clauses.

Consider the table EMPLOYEE and DEPARTMENT


Emp(Empno, Ename, Deptno, Deptname,Jobid, Salary,hiredate).

a. Display total salary spent for each job category.

ANS : SELECT SUM(SALARY) FROM EMP GROUP BY DEPTNAME;

b. Display lowest paid employee details under each department.

ANS : SELECT MIN(SALARY) FROM EMPLOYEE GROUP BY DEPTNAME;

c. Display number of employees working in each department and their department name.
ANS : SELECT COUNT(*) ,DEPTNAME FROM EMPLOYEE GROUP BY DEPTNAME;
d. Display the details of employees with the salary in increasing order.
ANS : SELECT * FROM EMPLOYEE ORDER BY SALARY;
e. List the number of employees from every department with sorted order(ascending).
ANS : SELECT COUNT(*) FROM EMP GROUP BY DEPTNO ORDER BY DEPTNO;

7. Write Query Using Inner and Outer Join


1. Perform RIGHT JOIN on EMP and DEPT table.
ANS : SELECT * FROM EMP RIGHT OUTER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;
DMS Practical Exam Questions

SELECT
2. Perform INNER JOIN on EMP and DEPT table.
ANS : SELECT * FROM EMP INNER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

3. Perform LEFT JOIN on EMP and DEPT table.


ANS : SELECT * FROM EMP LEFT OUTER JOIN DEPT ON EMP.DEPTNO=DEPT.DEPTNO;

8. Create and Modify View.


1. Create dept view on dept table
ANS : CREATE VIEW DEPT_VIEW AS SELECT DEPTNO,DEPTNAME,LOCATION FROM DEPT_TABLE.
2. Insert new record in dept_view view.
ANS : INSERT INTO DEPT VALUES (10,’XYZ’,’SOLAPUR’);
3. Modify location of deptno 10 of dept_view.
ANS : UPDATE DEPT_VIEW SET LOCATION=’PUNE’ WHERE DEPTNO=10;
4. Delete the record of deptno 20 from dept view .
ANS : DELETE FROM DEPT_VIEW WHERE DEPTNO=20;
5. Delete the view dept view.
ANS : DROP VIEW DEPT_VIEW.

9. Write Query for Indexes and Synonyms.


1.Create simple index dept simple index on dept table.
ANS : CREATE INDEX IND1 ON DEPT(DEPT_ID);
2.Create composite index dept composite index on dept table.
ANS : CREATE INDEX IND2 ON DEPT(DEPT_ID,DEPTNAME);
3.Drop index dept simple index and dept composite index.
ANS : DROP INDEX IND1;
DROP INDEX IND2;
4.Create synonym dept synonym on dept table.
ANS : CREATE SYNONYM DEPT_S FOR DEPT;
5.Drop synonym dept synonym.
ANS : DROP SYNONYM DEPT_S.
DMS Practical Exam Questions

10. Write query for sequence and synonyms.


1.Create sequence dept sequence on dept table.
ANS : CREATE SEQUENCE DEPT_SEQUENCE START WITH 1 INCREMENT BY 1 MAXVALUE 100
NOCYCLE;
2.Alter sequence dept_sequence.
ANS : ALTER SEQUENCE DEPT_SEQUENCE INCREMENT BY 2;
3.Create synonym dept synonym on dept table.
ANS : CREATE SYNONYM DEPT_S FOR DEPT;
4.Drop synonym dept synonym.
ANS : DROP SYNONYM DEPT_S.

11. PL/SQL Programs Using For loop.


Write a PL/SQL program to display 1 to 10 numbers in reverse order using for loop
DECLARE
I INT:=10;
BEGIN
FOR I IN 1..10 LOOP
DBMS_OUTPUT.PUT_LINE(I);
END LOOP;
END;
DMS Practical Exam Questions

12. PL/SQL Programs Using While loop.

Write PL/SQL program to find factorial of number 5 using while loop.


DECLARE
v_no NUMBER := &no;
f NUMBER := 1;
n_temp NUMBER;
BEGIN
n_temp := v_no;
WHILE v_no > 0
LOOP
f := f * v_no;
v_no := v_no – 1;
END LOOP;
DBMS_OUTPUT.PUT_LINE(‘factorial of ‘ || n_temp ||’ is ‘ || f);
END;

13.PL/SQL Programs Using NESTED If-Else loop.


Write a PL/SQL program to accept three numbers and display the largest number.
DECLARE
A INT:=:A;
B INT :=:B;
C INT :=:C;
BEGIN
IF (A>B ) AND (A>C) THEN
DBMS_OUTPUT.PUT_LINE(‘A IS GREATER’||A);
ELSE IF (B>A) AND (B>C) THEN
DBMS_OUTPUT.PUT_LINE(‘B IS GREATER’||B);
ELSE
DBMS_OUTPUT.PUT_LINE(‘C IS GREATER’||C);
END IF;
END IF;
END;
DMS Practical Exam Questions

14. PL/SQL Programs Using For Loop.


Write a PL/SQL program to display even numbers between 1 to 100.
DECLARE
NUM INT;
BEGIN
DBMS_OUTPUT.PUT_LINE('EVEN NUMBERS: ');
FOR NUM IN 1..100
LOOP
IF MOD(NUM,2)=0 THEN
DBMS_OUTPUT.PUT_LINE(' '||NUM);
END IF;
END LOOP;
END;

DMS Practical Exam Questions

15. PL/SQL Programs Based on Implicit and Explicit Cursors.


Display names of top 5 highest paid salary employees.

DECLARE CURSOR C_HISAL IS SELECT ENAME,SALARY FROM EMP ORDER BY SALARY DESC;
SAL_TEMP C_HISAL%ROWTYPE;
BEGIN OPEN C_HISAL;
LOOP FETCH C_HISAL INTO SAL_TEMP;
DBMS_OUTPUT.PUT_LINE(SAL_TEMP.ENAME || ' ' || SAL_TEMP.SALARY);
EXIT WHEN C_HISAL%ROWCOUNT = 5;
END LOOP;
CLOSE C_HISAL;
END

16. PL/SQL Programs Using Based on Exception Handling.

Write a PL/SQL code to check whether specified employee is present in Emp table or
not. Accept empno from user. If employee does not exist display message using
exception handling.(Use No_data_found exception)
DECLARE
NO EMP.EMPNO%TYPE;
BEGIN
NO:=&NO;
SELECT EMPNO INTO NO FROM EMP WHERE EMPNO=NO;
DBMS_OUTPUT.PUT_LINE('EMPNO IS PRESENT: '||NO);
EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('EMPNO NOT
PRESENT');
END;
DMS Practical Exam Questions

17. PL/SQL Programs Using Based on Exception Handling.

Write a PL/SQL program which accept the customer ID from the user if user enters an
invalid ID then the exception invalid_id is raised using exception handling.

DECLARE
C_ID NUMERIC(10);
INVALID_ID_EXCEPTION EXCEPTION;
BEGIN
C_ID:=&C_ID;
IF(C_ID<0) THEN
RAISE INVALID_ID_EXCEPTION;
END IF;
EXCEPTION
WHEN INVALID_ID_EXCEPTION THEN
DBMS_OUTPUT.PUT_LINE('INVALID CUSTOMER ID');
END;

18. Write PL/SQL Code to Create Procedures.


Write procedure to update the salary of all employees by 25%.
CREATE OR REPLACE PROCEDURE INC_SAL
IS
BEGIN
UPDATE EMPLOYEE
SET SALARY=SALARY+SALARY*0.25;
END INC_SAL;

CALLING PROCEDURE :
BEGIN
INC_SAL;
END;
DMS Practical Exam Questions

19. Write PL/SQL Code to Create Functions.


Write Function to calculate factorial of given no.

20. Executing DCL Commands Using SQL Create Users,Grant Privileges To Users ,Revoke
Privileges From Users.

Write Output of the Following queries:


A. Create user jyoti identified by j@123;
ANS : CREATE USER JYOTI IDENTIFIED BY J@123;
B. Grant select,insert,update on Emp to jyoti;
ANS : GRANT SELECT ,INSERT,UPDATE ON EMP TO JYOTI;
C. Revoke select,insert,update on Emp from jyoti;
ANS : REVOKE SELECT ,INSERT,UPDATE ON EMP FROM JYOTI;

You might also like