DBMS Pratical
DBMS Pratical
DBMS Pratical
DBMS practical
Index
S.NO 01. NAME OF PARTICULARS Create table Student1 and Student2 and show the functionalities of SQL operations and Built In functions. Insert about 10 rows as are appropriate to solve the following queries. ARITHMETIC OPERATOR COMPARISON OPERATOR LOGICAL OPERATOR SET OPERATIONS SORTING AND GROUPING FUNCTIONS PAGE NO 3 Date 18-11-09 SIGN
02.
18-11-09
7 9 17 19 23 25 27 29 29 31
19-11-09 20-11-09 22-11-09 24-11-09 25-11-09 26-11-09 27-11-09 30-11-09 1-12-09 2-12-09
AGGREGATE(GROUP)FUNCTIONS
MISCELLANEOUS FUNCTIONS DATE FUNCTIONS NUMERIC FUNCTIONS STRING FUNCTIONS
pg. 2
DBMS practical
Table 1 Index
S.NO I](a) NAME OF PARTICULARS Create the above tables with the given specifications and constraints. Insert about 10 rows as are appropriate to solve the following queries. List the names of the teachers teaching computer subjects. List the names and cities of all the staff working in your college. List the names and cities of all staff working in your college who earn more than 15000. Find the staffs whose names start with M or R and ends with A and/or 7 characters long. Find the staffs whose date of joining is 2005. Modify the database so that staff N1 now works in C2 college. Find the classes that T1 do not teach at present session. Find the colleges who have most no. of staffs. Find the colleges whose average salary is more than average salary is more than C2. Find the colleges that has the smallest payroll. Find the colleges where the total salary is greater than the average salary of all colleges. PAGE NO 38 Date 05-01-10 SIGN
(b)
38
05-01-10
(c)
44
06-01-10
(d)
44
06-01-10
(e)
44
06-01-10
(f)
45
11-01-10
(g) (h)
45 46
11-01-10 11-01-10
(j)
47
12-01-10
J(a) (c)
47 48
12-01-10 12-01-10
(d) (e)
48 48
12-01-10 12-01-10
pg. 3
DBMS practical
(f)
List maximum, average, minimum salary of each college. List the names of the teachers, departments teachings in more than one department. Acquire details of staffs by name in a college or each college. Find the names of the staff that earn more than each staff of C2 college. Give all lecturers a10% rise in salary unless their salary becomes greater than 40000 in such case give 5% rise. List names of employees in ascending order according to salary who are working in your college or all colleges.
49
14-01-10
(F)(a)
50
14-01-10
(b)
50
14-01-10
(c)
52
14-01-10
(d)
55
15-01-10
(f)
54
15-01-10
F(F)(a Create a view having fields sname, cname, ) dept, DOJ, and post. (b) Create a view consisting of cname, average salary and total salary of all staffs in that college. Select the colleges having highest and lowest average salary using above views. List the staff names of the department using above views.
55
15-01-10
56
15-01-10
(c)
57
15-01-10
(d)
57
15-01-10
pg. 4
DBMS practical
Table 2 Index
S.NO a. NAME OF PARTICULARS Create the above tables with the given specifications and constraints. Insert about 10 rows as are appropriate to solve the following queries. Get full details of all student who took admission this year class wise. List the number of admissions in your class in every year. List the students in the session who are not in the colleges in the same city they live in. List the students in colleges in your city and also live in your city. PAGE NO Date 61 16-01-10 SIGN
b.
62
16-01-10
c.
64
18-01-10
e.(b)
65
18-01-10
e.(c) e.(d)
66 66
18-01-10 18-01-10
pg. 5
DBMS practical
Table 3 Index
S.NO Q1. NAME OF PARTICULARS Create the above tables with the given specifications and constraints. Insert about 10 rows as are appropriate to solve the following queries. List the students who were present in paper of a subject. List all roll no. who have passed in first division. List all students in BCA-II who have scored higher than average (i)in your college (ii)in every college Q6. List the highest score, average and minimum score in BCA_II (i)in your college (ii)in every college 74 18-01-10 PAGE NO 67 Date 17-01-10 SIGN
Q2.
67
17-01-10
Q3.
72
17-01-10
Q4. Q5.
73 74
18-01-10 18-01-10
pg. 6
DBMS practical
QUESTION 4
Write PL/SQL codes of the following:-
S.NO Q1.
NAME OF PARTICULARS Print name of employees with their manager names using cursor. Print Fibonacci series. Find the factorial of any numbers. Update the salary of employees by 25% if the salary is greater than 3000 else update the salary to 3000. Find number is prime or not prime
PAGE NO 76
Date
SIGN
78 80 81
Q5.
82
pg. 7
DBMS practical
a) Create the above tables with the given specification and constraints. b) Insert about 10 rows as are appropriate to solve the following queries. QUERIES: create table student1(Name varchar(12),Class varchar(8),Rollno number(4),Marks1 number(3),Marks2 number(3),Marks3 number(3)); OUTPUT: Table created. QUERIES: SQL> insert into student1 values('&Name','&Class',&Rollno,&Marks1, &Marks2, &Marks3,'); Enter value for Name:HANIF Enter value for Class: BCA-II Enter value for Rollno: 101 Enter value for Marks1: 55 Enter value for Marks2: 65 Enter value for Marks3: 77 1 row created.
pg. 8
------------ -------- --------- --------- --------- --------Hanif Ankit BCA-II BCA-II 101 102 103 104 105 106 107 108 109 110 55 63 21 56 55 10 11 45 88 44 65 60 55 84 65 20 22 98 77 55 77 87 87 95 77 30 33 33 61 33
Kuvendra BCA-II Mirdul Aditi Sonia Nupur Ankit Rajesh Atif BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II
10 rows selected. QUERIES: create table student2(Name varchar(12),Class varchar(8),Rollno number(4),Marks1 number(3),Marks2 number(3),Marks3 number(3)); OUTPUT: Table created. QUERIES: SQL> insert into student2 values('&Name','&Class',&Rollno,&Marks1, &Marks2, &Marks3,'); Enter value for Name: Hanif Enter value for Class: BCA-II
pg. 9
DBMS practical Enter value for Rollno: 1 Enter value for Marks1: 56 Enter value for Marks2: 66 Enter value for Marks3: 86 1 row created.
------------ --------- --------- --------- --------- -------Kuvendra Hanif Ankit Rajesh Akash Sonia Aditi Nupur Abash Prakesh BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II 1 2 3 4 5 6 7 8 9 10 56 87 87 63 55 89 89 89 87 88 66 88 99 66 65 99 99 87 98 98 86 24 33 90 77 33 33 88 89 78
10 rows selected.
pg. 10
DBMS practical
Arithmetic operators
1.) ADDITIONS (+):QUERIES: SQL> UPDATE STUDENT2 SET MARKS3=MARKS3+5 WHERE ROLLNO=2;
1 row updated. OUTPUT: SQL> SELECT * FROM STUDENT2 WHERE ROLLNO=2; NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
NAME
CLASS
pg. 11
DBMS practical
NAME
CLASS
NAME
CLASS
pg. 12
DBMS practical
COMPARISON OPERATOR
1.) EQUALITY (=): QUERIES: SQL> SELECT * FROM STUDENT2 WHERE ROLLNO=105; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
2.) LESS THAN (<): QUERIES: SQL> SELECT * FROM STUDENT1 WHERE MARKS3<70; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Aditi Mirdul Ankit Rajesh BCA-II BCA-II BCA-II BCA-II 106 107 108 109 110 10 11 45 88 44 20 22 98 77 55 30 33 33 61 33
Kuvendra BCA-II
pg. 13
DBMS practical 3.) GREATER THAN (>):QUERIES: SQL> SELECT * FROM STUDENT2 WHERE MARKS1>80; OUTPUT: NAME -----------Hanif Kuvendra Sonia Ankit Kishan Atif Aditi CLASS --------BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II ROLLNO --------2 3 6 7 8 9 10 MARKS1 --------87 87 89 89 89 87 88 MARKS2 --------88 99 99 99 87 98 98
MARKS3 --------29 66 33 33 44 89 78
7 rows selected. 4.) LESS THAN EQUAL TO (<=):QUERIES: SQL> SELECT * FROM STUDENT2 WHERE MARKS3>=80; OUTPUT: NAME -------Aashish SONIA Atif CLASS --------BCA-II BCA-II BCA-II 4 9 ROLLNO MARKS1 MARKS2 MARKS3 --------1 --------56 63 87 --------66 66 98 --------86 80 89
pg. 14
DBMS practical 5.) GREATER THAN EQUAL TO(>=):QUERIES: SQL> SELECT * FROM STUDENT2 WHERE MARKS3<=50; OUTPUT: NAME -------Hanif Sonia Ankit Nupur CLASS --------BCA-II BCA-II BCA-II BCA-II ROLLNO MARKS1 MARKS2 MARKS3 --------2 6 7 8 --------87 89 89 89 --------- ----------88 99 99 87 29 33 33 44
6.) NOT EQUAL TO (!= OR <> OR ^=):QUERIES: SQL> SELECT * FROM STUDENT2 WHERE MARKS2!=99; OUTPUT: NAME -----------Kuvendra Hanif Sonia Mirdul Atif Atif Aditi CLASS --------BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II BCA-II ROLLNO MARKS1 MARKS2 MARKS3 --------1 2 3 4 5 6 7 56 87 63 55 89 87 88 --------66 88 66 65 87 98 98 --------86 29 80 77 44 89 78 ---------
pg. 15
SQL> SELECT * FROM STUDENT2 WHERE MARKS2 IN(66,99); OUTPUT: NAME --------Aashish CLASS --------BCA-II ROLLNO MARKS1 MARKS2 MARKS3 --------1 2 3 4 5 --------56 87 63 89 89 --------66 99 66 99 99 --------86 66 80 33 33
8.) NOT IN:QUERIES: SQL> SELECT * FROM STUDENT2 WHERE MARKS2 NOT IN(66,99); OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ --------- --------- --------- --------- --------Hanif BCA-II2 BCA-II BCA-II 9 10 87 105 8 87 88 89 98 98 88 55 87 89 78 29 65 44 77
Bhumika Kishan
pg. 16
DBMS practical 9.) IS NULL:QUERIES: SQL> SELECT * FROM STUDENT1 WHERE MARKS1 IS NULL; OUTPUT: no rows selected
10.) IS NOT NULL:QUERIES: SQL> SELECT * FROM STUDENT1 WHERE MARKS1 IS NOT NULL; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Hanif Annu Brajesh Smriti Bhumika Aditi BCA-IIA-I BCA-II 101 102 63 103 104 105 10 11 45 109 44 55 20 22 98 88 55 55 60 21 56 65 30 33 33 77 33 61 65 87 55 84 77 87 95 77
BCA-II106
RajeshBCA-IIom-III Kuvendra
BCA-II110
10 Rows selected.
pg. 17
DBMS practical
11.)LIKE :QUERIES: SQL> SELECT * FROM STUDENT1 WHERE NAME LIKE 'A%'; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Hanif Annu BCA-IIA-I BCA-II 101 102 63 55 60 65 87 77
12.)NOT LIKE :QUERIES: SQL> SELECT * FROM STUDENT1 WHERE NAME NOT LIKE 'A%'; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Brajesh Smriti Bhumika Aditi BCA-IIA-III BCA-IIA-I BCA-II 103 104 105 10 11 45 109 44 55 20 22 98 88 55 21 56 65 30 33 33 77 33 61 55 84 77 87 95
BCA-II106
RajeshBCA-IIom-III Kuvendra
BCA-II110
pg. 18
DBMS practical
13.)ALL :QUERIES: SQL> SELECT MARKS1 FROM STUDENT1 WHERE MARKS1<ANY(SELECT MARKS1 FROM STUDENT2); OUTPUT: MARKS1 --------55 63 21 56 55 10 11 45 88 44 10 Rows selected.
14.)ANY OR SOME :QUERIES: SQL> SELECT MARKS1 FROM STUDENT1 WHERE MARKS1<ALL(SELECT MARKS1 FROM STUDENT2);
pg. 19
10.)
BETWEEN :-
QUERIES: SQL> SELECT * FROM STUDENT1 WHERE MARKS2 BETWEEN 50 AND 75; OUTPUT: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Hanif Annu Brajesh Bhumika Kuvendra BCA-IIA-I BCA-II 101 102 63 103 105 55 44 55 60 21 65 55 65 87 55 77 33 87 77
BCA-IIA-III BCA-II
BCA-II110
Logical Operator
pg. 20
DBMS practical
1.)AND
Syntax: SQL> select * from student1 where rollno=109 and marks2=77; Output: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
2.)OR
Syntax:
NAME
CLASS
------------ -------- --------- --------- --------- --------Hanif Sanjay BCA-IIA-I BCA-II 101 105 55 55 65 65 77 77
3.)NOT
Syntax:
pg. 21
NAME
CLASS
------------ -------- --------- --------- --------- --------Hanif Annu Brajesh Smriti Sanjay Aditi BCA-IIA-I BCA-II 101 102 63 103 104 105 10 11 45 109 55 20 22 98 88 55 60 21 56 65 30 33 33 77 61 65 87 55 84 77 87 95 77
RajeshBCA-IIom-III
9 rows selected.
Set operations
pg. 22
DBMS practical
1.) UNION
Syntax:
------------ --------- --------- --------- --------- --------Aashish Hanif Hanif Annu Kuvendra Bhumika Brajesh BCA-II1 BCA-II2 BCA-IIA-I BCA-II 87 101 102 87 63 103 87 88 98 98 44 89 8 11 109 45 5 99 55 89 22 88 98 78 33 65 77 99 87 33 77 33 98 99 61 63 99 66 21 89 78 55 33 88 33 56 88 55 60 33 90 55 87 66 24 65 87 77 86
BCA-II 110 7
89 105
pg. 23
20 rows selected.
Output:
NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ --------- --------- --------- --------- --------Aashish Hanif BCA-II1 BCA-II2 87 56 88 87 63 5 99 89 8 87 88 101 102 63 103 89 98 98 55 60 21 99 87 89 78 65 87 55 87 77 66 24 99 66 78 33 33 88 33 90 98 99 86
BCA-II 3 BCA-II 4
BCA-IIom-III 89 7
BCA-IIA-I BCA-II
BCA-IIA-III
pg. 24
DBMS practical Smriti Sanjay Aditi BCA-IIA-I BCA-II BCA-II 106 105 10 11 45 109 44 104 55 20 22 98 88 55 56 65 30 33 33 77 33 61 84 77 95
RajeshBCA-IIom-III Kuvendra
BCA-II 110
20 rows selected.
3.) INTERSECTION
Syntax: SQL> SELECT * FROM STUDENT1 INTERSECT SELECT * FROM STUDENT2; Output: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ --------- --------- --------- --------- --------Hanif Annu Brajesh Kuvendra BCA-IIA-I BCA-II 101 102 63 103 44 22 88 98 20 56 55 60 21 55 33 77 33 30 84 95 61 65 87 55 33 87 77
MirdulBCA-II 107 RajeshBCA-IIom-III Ankit Aditi Smriti BCA-II 108 BCA-II 106 BCA-IIA-I
109 45 10 104
9 rows selected.
DBMS practical Syntax: SQL> select * from student1 order by name; Output: NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Hanif Annu Bhumika Brajesh Kuvendra BCA-IIA-I BCA-II BCA-II BCA-IIA-III BCA-II110 11 109 45 10 104 101 102 105 103 44 22 88 98 20 56 63 55 21 55 33 77 33 30 84 95 61 55 60 65 55 33 65 87 77 87 77
10 rows selected.
------------ -----------
pg. 27
DBMS practical Hanif Annu Bhumika Brajesh Kuvendra Mirdul Rajesh Ankit Aditi Smriti 107 109 108 106 104 101 102 105 103 110
10 Rows selected.
03.)NAMES IN DESCENDING ORDER Syntax: SQL> select * from student1 order by name desc; Output:
NAME CLASS ROLLNO MARKS1 MARKS2 MARKS3
------------ -------- --------- --------- --------- --------Smriti Aditi Ankit BCA-IIA-I BCA-II106 BCA-II108 104 10 45 109 11 22 20 98 88 33 56 30 33 77 61 84 95
RajeshBCA-IIom-III MirdulBCA-II107
pg. 28
DBMS practical Kuvendra Brajesh Bhumika Annu Hanif BCA-II110 BCA-IIA-III BCA-II BCA-II BCA-IIA-I 105 102 101 44 103 55 63 55 55 21 65 60 65 33 55 77 87 77 87
10 rows selected.
AGGREGATE(GROUP)FUNCTIONS
1.)AVG Syntax:
pg. 29
DBMS practical SQL> SELECT AVG (Marks1)"AVERAGE" FROM STUDENT1; Output: AVERAGE --------44.8 2.)COUNT Syntax: SQL> SELECT COUNT (*) FROM STUDENT1 WHERE MARKS3=77; Output: COUNT(*) --------2 3.)MAX Syntax: SQL> SELECT MAX(MARKS2)FROM STUDENT2;
4.)MIN
Syntax: SQL> SELECT MIN(MARKS2)FROM STUDENT2;
pg. 30
5.)SUM
Syntax: SQL> SELECT SUM(MARKS2)FROM STUDENT2;
MISCELLANEOUS FUNCTIONS
01.) NVL
Syntax:
pg. 31
DBMS practical
02.) DECODE
Syntax: SELECT NAME,DECODE(MARKS2,99,'A+',98,'A+',88,'B',87,'C',66,'D',65,'FAIL')"GRADE" FROM STUDENT2;
pg. 32
10 rows selected.
DATE FUNCTIONS
1.) Date
Syntax: SQL> select sysdate from dual;
pg. 33
2.) ADD_MONTHS
Syntax: SQL> select add_months(sysdate,2) from dual; Output: ADD_MONTH --------23-MAR-10
3.) LAST_DAY
Syntax: SQL> select last_day('12-feb-2010')from dual; Output: LAST_DAY( --------28-FEB-10
4.) ROUND
Syntax: SQL> SELECT ROUND(SYSDATE,'MONTH')"FIRST OF THE MONTH"FROM DUAL; Output: FIRST OF
pg. 34
5.)TRUNC
Syntax: SELECT TRUNC(SYSDATE,'YEAR')"FIRST OF THE YEAR"FROM DUAL; Output: FIRST OF --------01-JAN-10
5.) NEXT_DAY
Syntax: SQL> select next_day(sysdate,'sunday') from dual; Output: NEXT_DAY( --------24-JAN-10
NUMERIC FUNCTIONS
01.TRUNC
Syntax: SQL> SELECT TRUNC(858.350325)FROM DUAL; Output:
pg. 35
02. POWER
Syntax: SQL> select power(6,2)from dual; Output: POWER(6,2) ---------36 03. Round Syntax: SQL> select round(365.589,2)from dual; Output: ROUND(365.589,2) ---------------365.59
04.) TRUNC
Syntax: SQL> select trunc(54.3698745231452,2)from dual; Output: TRUNC(54.3698745231452,2) -------------------------
pg. 36
05.)CEIL
Syntax: SQL> select ceil(5020.25)from dual; Output: CEIL(5020.25) ------------5021
06.)SQRT
Syntax: SQL> select sqrt(9)from dual; Output: SQRT(9) --------3
STRING FUNCTIONS
01.)LENGTH
Syntax: SQL> select length('NITESH')from dual; Output:
pg. 37
02.)UPPER CASE
Syntax: SQL> select upper('pritosh') from dual; Output: UPPER(' ------PRITOSH
03.)LOWER CASE
Syntax: SQL> select lower('Abhinav Singh')from dual; Output: LOWER('ABHINA ------------abhinav singh
pg. 38
05.LTRIM
Syntax: SQL> select ltrim ('UNWANTED','UN') from dual; Output: LTRIM( ----WANTED
06.RTRIM
Syntax: SQL> select rtrim ('NITESH','ESH')FROM DUAL; Output: RTR --NIT
07.LPAD
Syntax: SQL> select lpad('NITESH','10','$') from dual; Output: LPAD('NITE ----------
pg. 39
08.RPAD
Syntax: SQL> select rpad ('NITESH','10','$') from dual; Output: RPAD('NITE ---------NITESH$$$$
09.TRANSLATE
Syntax: SQL> select translate('KNOWLEDGE','K','P') from dual; Output: TRANSLATE --------PNOWLEDGE
10.REPLACE
Syntax: SQL> select replace('NITESH','e','sh') from dual; Output: REPLAC ------
pg. 40
11.SUBSTR
Syntax: SQL> select substr('Christ College',8,7) from dual; Output: SUBSTR( ------College
pg. 41
DBMS practical
Using the following dataBCA-IIA-IIse, Colleges (cname, city, address, phone, afdate) Staff (sid, sname, saddress, contacts) Staffjoins (sid, cname, dept, DOJ, post, salary) Teachings (sid, class, papered, fsession, tsession) pg. 42
DBMS practical
QUERIES:
OUTPUT:
pg. 43
DBMS practical
STAFF TABLE
QUERIES: create table staffs(sid number(10),sname number(10),primary key(sid)); OUTPUT: Table created. QUERIES: SQL> insert into staffs values('&sid','&sname','&saddress','&contacts'); varchar(30),saddress varchar(40),contacts
pg. 44
DBMS practical Enter value for sid: 11 Enter value for sname: Asim Sir Enter value for saddress: Kumarpara Enter value for contacts: 942420001 OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM STAFFS; OUTPUT: SID SNAME SADDRESS CONTACTS
--------- -------------------- ---------------------- --------101 Asim Sir 102 Sushil Sahu 103 Garima Gupta 104 Siji Jestus John 105 Sangita Mam 106 Shankar 107 Jyota Mam 108 Subbu Sir 109 Pranab Das 110 Pallavi Mam Kumarpara Geedam Road Nayapara Freezerpur 942420001 942420002 942420003 942420004 942420005
942420006 942420007
10 rows selected.
pg. 45
DBMS practical
STAFFJOINS TABLE
QUERIES: create table StaffJoins(sid number(10),cname varchar(40),Dept varchar(40),DOJ date,Post varchar(50),Salary number(10),primary key(cname)); OUTPUT: Table created. QUERIES: SQL> insert into staffjoins values('&sid','&cname','&dept','&doj','&post','&salary'); Enter value for sid: 101 Enter value for cname: Christ College Enter value for dept: Computer Enter value for doj: 01-Jan-2004 Enter value for post: Principal Enter value for salary: 30000
OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM STAFFJOINS; OUTPUT: SQL> select * from staffjoins;
SID CNAME
DEPT
DOJ
POST
SALARY
pg. 46
DBMS practical 101 Christ College 102 PG College 103 Surya College 104 Dantshwari College 105 MATS College 106 Rungta College 107 Shankrachayar College 108 Engineering College 109 Disha College 110 Maharaja College 10 rows selected. Computer Computer Commerce Sports Biology Physics 01-JAN-04 Principal 10-FEB-05 HOD 15-MAR-05 Teacher 29-APR-06 Teacher 11-SEP-04 Professor 20-MAY-09 Teacher 30000 35000
Computer Maths
01-JUN-07 Principal
Biology Arts
TEACHINGS TABLE
pg. 47
DBMS practical
SQL> INSERT INTO TEACHINGS VALUES('&SID','&CLASS','&PAPERID','&FSESSION','&TSESSION'); Enter value for sid: 1 Enter value for class: BCA-IIA-I Enter value for paperid: 1 Enter value for fsession: Yes Enter value for tsession: No OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM TEACHINGS; OUTPUT: SQL> select * from teachings;
SID CLASS
--------- ---------- ---------- ---------- ---------1 BCA-IIA-I 2 BCA-II 2 3 BCA-II 3 4 BCA-IIA-III 4 5 BCA-IIA-III 5 6 BCA-IIA-I 7 BCA-II 7 8 B.COM-II 8 9 B.COM-III 9 6 no yes yes 1 no yes no no yes yes no yes yes yes yes yes yes yes no
pg. 48
10 rows selected.
SUBJECT TABLE
QUERIES: create table Subject(paperid number(5),subject varchar(25),paperno number(5),papername varchar(6)); OUTPUT: Table created. QUERIES: SQL> INSERT INTO SUBJECT VALUES('&PAPERID','&SUBJECT','&PAPERNO','&PAPERNAME'); Enter value for paperid: 1 Enter value for subject: Linux Enter value for paperno: 1 Enter value for papername: A-101 OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM SUBJECT; OUTPUT: PAPERID SUBJECT PAPERNO PAPERN
pg. 49
DBMS practical 3 Networking 4 DBMS 5 Software Engineering 6 PC Software 7 Maths 8 Accounts 9 POM 10 English 3 A-101 4 A-101 5 A-101 6 A-101 7 A-101 8 A-101 9 A-101 10 A-101
10 rows selected.
pg. 50
DBMS practical
(D) List the names and cities of all the staff working in your college.
QUERIES: SQL> select SNAME,SADDRESS,CNAME FROM STAFFS,STAFFJOINS WHERE STAFFJOINS.CNAME='Christ College' AND STAFFS.SID=STAFFJOINS.SID; OUTPUT: SNAME SADDRESS CNAME
Que (E) List the names and cities of all staff working in your college who earn more than 15000.
QUERIES: SQL> select S.SNAME,S.SADDRESS from Staffs S,StaffJoins SJ where S.SID=SJ.SID and Salary>15000 and CNAME='Christ College'; OUTPUT: SNAME SADDRESS
(F) Find the staffs whose names start with M or R and ends with A and/or 7 characters long.
QUERIES: SQL> SELECT SNAME FROM STAFFS WHERE SNAME LIKE 'M%' OR SNAME LIKE 'D%' AND SNAME LIKE '%A' OR LENGTH (SNAME) =7; OUTPUT: SNAME --------------------
pg. 51
--------- ---------------------------- ------------ --------- ------------ --------102 PG College 103 Surya College Computer 10-FEB-05 HOD 35000 25000 25000
Que (H) Modify the dataBCA-IIA-IIse so that staff N1 now works in C2 college.
QUERIES: SQL> UPDATE STAFFJOINS SET CNAME='POLITECTNIC' WHERE SID='108'; OUTPUT: 1 row updated. SQL> SELECT * FROM STAFFJOINS; OUTPUT: SQL> SELECT * FROM STAFFJOINS; SID CNAME DEPT DOJ POST
--------- ---------------------------- ------------ --------- -----------101 Christ College 102 PG College Computer Computer 01-JAN-04 Principal 10-FEB-05 HOD
pg. 52
DBMS practical 103 Surya College 104 Dantshwari College 105 MATS College 106 Rungta College 107 Shankrachayar College 108 POLITECTNIC 109 Disha College 110 Maharaja College Commerce Sports Biology Physics 15-MAR-05 Teacher 29-APR-06 Teacher 11-SEP-04 Professor 20-MAY-09 Teacher 01-JUN-07 Principal
Computer Maths
Biology Arts
10 rows selected.
Que (J) Find the classes that T1 do not teach at present session.
QUERIES: SQL> SELECT CLASS FROM Teachings where Tsession='no'; OUTPUT: CLASS ---------BCA-IIA-I B.COM-II
Que j(a) Find the colleges who have most no. of staffs.
QUERIES: SELECT CNAME,COUNT(*)"NO OF STAFFS" FROM STAFFJOINS GROUP BY CNAME HAVING COUNT(*)=(SELECT MAX(COUNT(*)) FROM STAFFJOINS GROUP BY CNAME);
pg. 53
---------------------------- -----------Christ College Dantshwari College Disha College MATS College Maharaja College PG College POLITECTNIC Rungta College Shankrachayar College Surya College 10 rows selected. 1 1 1 1 1 1 1 1 1 1
j(c) Find the colleges whose average salary is more than average salary is more than C2.
QUERIES: SQL> SELECT CNAME,AVG(Salary)FROM STAFFJOINS GROUP BY CNAME AVG(Salary)>(SELECT AVG(Salary)from Staffjoins where CNAME='Christ College'); OUTPUT: CNAME AVG(SALARY) HAVING
pg. 54
DBMS practical
SELECT CNAME,MIN(SALARY )"SALARY" FROM STAFFJOINS GROUP BY CNAME HAVING MIN(SALARY)=(SELECT MIN(MIN(SALARY))FROM STAFFJOINS GROUP BY CNAME); OUTPUT: CNAME SALARY
(e) Find the colleges where the total salary is greater than the average salary of all colleges.
QUERIES: SELECT CNAME,SUM(SALARY)FROM STAFFJOINS GROUP SUM(SALARY)>(SELECT AVG(SALARY)FROM STAFFJOINS); OUTPUT: CNAME SUM(SALARY) BY CNAME HAVING
---------------------------- ----------Christ College MATS College Maharaja College PG College Rungta College Surya College 30000 25000 25000 35000 25000 25000
6 rows selected.
SELECT CNAME, MIN(SALARY)"MIN SALARY",MAX(SALARY)"MAX SALARY",AVG(SALARY)"AVG SALARY" FROM STAFFJOINS GROUP BY CNAME; OUTPUT: CNAME MIN SALARY MAX SALARY AVG SALARY
---------------------------- ---------- ---------- ---------Christ College Dantshwari College Disha College Engineering College MATS College Maharaja College PG College Rungta College Shankrachayar College Surya College 30000 30000 30000 20000 10000 20000 25000 25000
35000 25000
20000 25000
20000
25000
25000
10 rows selected. F(a) List the names of the teachers, departments teachings in more than one department. QUERIES: SQL> SELECT T1.SNAME,T2.DEPT FROM STAFFS T1,STAFFJOINS T2,(SELECT SID,COUNT(*)"SUM"FROM STAFFJOINS GROUP BY SID)T3 WHERE T1.SID=T3.SID AND T1.SID=T2.SID AND "SUM">1; OUTPUT: no rows selected
pg. 56
DBMS practical Que f(b) Acquire details of staffs by name in a college or each college. QUERIES:
SQL> SELECT SNAME,SADDRESS,CONTACTS,CNAME,DEPT,DOJ,POST,SALARY FROM STAFFS,STAFFJOINS WHERE STAFFS.SID=STAFFJOINS.SID; OUTPUT: SNAME SADDRESS CONTACTS CNAME DEPT
--------- ------------ --------Asim Sir Kumarpara 30000 942420001 Christ College Computer
01-JAN-04 Principal
942420002 PG College
Computer
Garima Gupta
Nayapara 25000
Commerce
15-MAR-05 Teacher
Freezerpur 20000
Sports
29-APR-06 Teacher
Sangita Mam
Biology
11-SEP-04 Professor
Shankar
Nayapara
Physics
pg. 57
Jyota Mam
Awintika Coloney
Computer
SNAME
SADDRESS
CONTACTS CNAME
DEPT
Freezerpur 20000
942420008 POLITECTNIC
Maths
Pranab Das
aasna 10000
Biology
15-AUG-10 Principal
Pallavi Mam
panrapara 25000
Arts
02-OCT-05 Teacher
10 rows selected.
F(c) Find the names of the staff that earn more than each staff of C2 college.
QUERIES: SQL> SELECT SNAME, SALARY, CNAME FROM STAFFS, STAFFJOINS WHERE STAFFS.SID=STAFFJOINS.SID AND SALARY>(SELECT SALARY FROM STAFFJOINS WHERE
pg. 58
DBMS practical
CNAME='Surya College' AND SALARY IN (SELECT MAX(SALARY) FROM STAFFJOINS GROUP BY CNAME)); OUTPUT: SNAME SALARY CNAME
-------------------- --------- ---------------------------Asim Sir Sushil Sahu 30000 Christ College 35000 PG College
F(d) Give all lecturers a10% rise in salary unless their salary becomes greater than 40000 in such case give 5% rise.
QUERIES: SQL> update StaffJoins set Salary=Salary+01.*Salary where post like 'Principal'and Salary<20000; OUTPUT: 1 row updated. QUERIES: SQL> SELECT * FROM STAFFJOINS; OUTPUT: SID CNAME DEPT DOJ POST SALARY
---- ---------------------------- ------------ --------- ------------ --------101 Christ College 102 PG College 103 Surya College 104 Dantshwari College 105 MATS College Computer Computer Commerce Sports Biology 01-JAN-04 Principal 10-FEB-05 HOD 15-MAR-05 Teacher 29-APR-06 Teacher 11-SEP-04 Professor 30000 35000 25000 20000 25000
pg. 59
DBMS practical 106 Rungta College 107 Shankrachayar College 108 POLITECTNIC 109 Disha College 110 Maharaja College Physics 20-MAY-09 Teacher 25000
Computer Maths
20000
Biology Arts
25000
10 rows selected.
F(f) List names of employees in ascending order according to salary who are working in your college or all colleges.
QUERIES:
OUTPUT:
SNAME
SALARY
-------------------- --------Siji Jestus John Jyota Mam Subbu Sir Pranab Das Garima Gupta Pallavi Mam Sangita Mam 20000 20000 20000 20000 25000 25000 25000
pg. 60
DBMS practical Shankar Asim Sir Sushil Sahu 25000 30000 35000
10 rows selected.
ff(a) Create a view having fields sname, cname, dept, DOJ, and post.
QUERIES:
SQL> create view faculty as select SNAME,CNAME,DEPT,DOJ,POST FROM STAFFS,STAFFJOINS WHERE STAFFS.SID=STAFFJOINS.SID;
View created.
OUTPUT: View created. QUERIES:
SNAME
CNAME
DEPT
DOJ
POST
-------------------- ---------------------------- ------------ --------- -----------Asim Sir Sushil Sahu Garima Gupta Christ College PG College Surya College Computer Computer 01-JAN-04 Principal 10-FEB-05 HOD 15-MAR-05 Teacher
Commerce
pg. 61
DBMS practical Siji Jestus John Sangita Mam Shankar Jyota Mam Subbu Sir Pranab Das Pallavi Mam Dantshwari College MATS College Rungta College Sports Biology Physics 29-APR-06 Teacher 11-SEP-04 Professor 20-MAY-09 Teacher
Computer
01-JUN-07 Principal
10 rows selected.
f)f)(b) Create a view consisting of cname, average salary and total salary of all staffs in that college.
QUERIES: SQL> CREATE VIEW DATA (CNAME,AVERAGE_SALARY,TOTAL_SALARY) AS SELECT CNAME,AVG(SALARY),SUM(SALARY)FROM STAFFJOINS GROUP BY CNAME;
CNAME
AVERAGE_SALARY TOTAL_SALARY
---------------------------- -------------- -----------Christ College Dantshwari College 30000 20000 30000 20000
pg. 62
DBMS practical
Disha College Engineering College MATS College Maharaja College PG College Rungta College Shankrachayar College Surya College 10000 20000 25000 25000 35000 25000 20000 25000 10000 20000 25000 25000 35000 25000 20000
25000
10 rows selected.
(f)(f)(c) Select the colleges having highest and lowest average salary using above views.
QUERIES:
SQL> SELECT CNAME,AVERAGE_SALARY FROM DATA WHERE AVERAGE_SALARY=(SELECT MAX(AVERAGE_SALARY)FROM DATA)OR AVERAGE_SALARY=(SELECT MIN(AVERAGE_SALARY)FROM DATA);
OUTPUT:
CNAME
AVERAGE_SALARY
Que (f)(f)(d) List the staff names of the department using above views.
QUERIES:
SQL> select SNAME,DEPT FROM FACULTY WHERE DEPT='Computer';
OUTPUT:
pg. 63
-------------------- -----------Asim Sir Sushil Sahu Jyota Mam Computer Computer Computer
QUESTION 2
Enrollment (enrollno, name, gender, DOB, address, phone) Admission (admno, enrollno, course, yearsem, date, cname) Colleges (cname, city, address, phone, afdate) FeeStructure (course, yearsem, fee) Payment (billno, admno, amount, pdate, purpose)
a: - Create the above tables with the given specifications and constraints. b: - Insert about 10 rows as are appropriate to solve the following queries. Enrollment Table
QUERIES: create table Enrollment (Enrollno number(4),Name varchar(12),Gender varchar(8),DOB date,Address varchar(18),Phone number(10)); OUTPUT:
pg. 64
insert into Enrollment values(111,'Amar','Male','01-Jan-2010','Kumarpara',942420001); OUTPUT: 10 row created. QUERIES: SQL> select * from Enrollment;
--------- ------------ -------- --------- ------------------ --------111 Amar 222 Brajesh 333 Dhamal 444 Javed 555 Ankit 666 Krishna 777 Jenny 888 Kuvendra 999 Priyanka Male Male Male Male Male Male 01-JAN-10 Kumarpara 02-FEB-09 Geedam Road 03-MAR-08 Nayapara 04-APR-00 Kumarpara 05-MAY-10 Freezerpur 942420001 942420001 942420001 942420001 942420001
Female 07-JUL-08 Awintika Coloney 942420001 Female 08-AUG-07 Freezerpur Female 09-SEP-10 aasna 942420001 942420001 942420001
10 rows selected.
pg. 65
DBMS practical
Admission Table
QUERIES: create table Admission (Admno number(4),Enrollno number(4),Course varchar(5),Yearsem varchar(14),ADate date,cname varchar(25)); OUTPUT: Table created. QUERIES: insert into Admission values(111, 101, 'BCA-IIA', 'I', '01-Jan-2009', 'Christ College');
OUTPUT: 10 row created. QUERIES: SQL> select * from admission; OUTPUT: ADMNO ENROLLNO COURS YEARSEM ADATE CNAME
--------- --------- ----- -------------- --------- ---------------------111 222 333 444 555 666 777 888 101 BCA-IIA I 102 BCA-IIA II 103 BCA-IIA III 104 BCA-IIOM I 105 BCA-IIOM II 106 BCA-IIOM III 107 BBCA-III 108 BBCA-IIII 01-JAN-09 Christ College 01-JAN-10 PG College 01-JAN-08 Surya College 01-JAN-10 Dantshwari College 01-JAN-09 MATS College 01-JAN-10 Rungta College 01-JAN-07 Shankrachayar College 01-JAN-07 Engineering College
pg. 66
DBMS practical 999 0 109 BBCA-IIIII 110 BSC I 01-JAN-07 Disha College 01-JAN-09 Maharaja College
10 rows selected.
Colleges Table
QUERIES: create table colleges(cname varchar(25),city varchar(12),address varchar(18),Phone number(11),afdate date,primary key(cname)); OUTPUT: Table created. QUERIES: insert into colleges values('Christ College','Jagdalpur','Geedam Road',0778222380,'01Jan-2007'); OUTPUT: 10 row created. QUERIES: SQL> select * from Colleges; OUTPUT: CNAME CITY ADDRESS PHONE AFDATE
pg. 67
DBMS practical Christ College PG College Surya College Dantshwari College MATS College Rungta College Jagdalpur Geedam Road Jagdalpur Dharampura Jagdalpur Geedam Road Jagdalpur Freezerpur Raipur Bhilai Bhilai Pandri Road Sector 16 Sector 36 778222380 01-JAN-07 778222381 02-FEB-10
10 rows selected.
FeeStructure Table
QUERIES: create table FeeStructure(Course varchar(5),YearSem varchar(5),Fee number(8)); OUTPUT: Table created. QUERIES: insert into FeeStructure values('BCA-IIA','I',18000);
pg. 68
DBMS practical
QUERIES: SQL> select * from admission; OUTPUT: ADMNO ENROLLNO COURS YEARSEM ADATE CNAME
--------- --------- ----- -------------- --------- ---------------------111 222 333 444 555 666 777 888 999 0 101 BCA-IIA I 102 BCA-IIA II 103 BCA-IIA III 104 BCA-IIOM I 105 BCA-IIOM II 106 BCA-IIOM III 107 BBCA-III 108 BBCA-IIII 109 BBCA-IIIII 110 BSC I 01-JAN-09 Christ College 01-JAN-10 PG College 01-JAN-08 Surya College 01-JAN-10 Dantshwari College 01-JAN-09 MATS College 01-JAN-10 Rungta College 01-JAN-07 Shankrachayar College 01-JAN-07 Engineering College 01-JAN-07 Disha College 01-JAN-09 Maharaja College
10 rows selected.
Payment Table
pg. 69
DBMS practical OUTPUT: Table created. QUERIES: insert into Payment values(110,01,10000,'01-Jan-2009','Fee'); OUTPUT: 10 row created.
--------- --------- --------- --------- ----110 220 330 440 550 660 770 880 990 1 2 3 4 5 6 7 8 9 10000 01-JAN-09 Fee 11000 02-FEB-09 Fee 12000 03-MAR-09 Fee 13000 04-APR-10 Fee 14000 05-MAY-10 Fee 15000 06-JUN-10 Fee 16000 07-JUL-10 Fee 17000 08-AUG-10 Fee 18000 09-SEP-10 Fee
pg. 70
10 rows selected.
C:-
Get full details of all student who took admission this year class wise.
QUERIES: SQL>SELECT ADMNO,ENROLLMENT.ENROLLNO,NAME,GENDER,DOB,CNAME,ADDRESS,PHONE,COURSE,YEA RSEM,ADATE FROM ENROLLMENT,ADMISSION WHERE ADMISSION.ADATE LIKE'%10' AND ENROLLMENT.ENROLLNO=ADMISSION.ADMNO ORDER BY COURSE;
OUTPUT:
GENDER DOB
CNAME
ADDRESS
--------- --------- ------------ -------- --------- ------------------------- -----------------PHONE COURS YEARSEM ADATE
--------- ----- -------------- --------222 222 Brajesh Male 02-FEB-09 PG College 01-JAN-10 Geedam Road
942420001 BCA-IIA II
444
444 Javed
Male
Kumarpara
942420001 BCA-IIOM I
666
666 Krishna
Male
Vindravan Coloney
DBMS practical QUERIES: SQL> select * from admission where course='BCA-IIA' order by adate; OUTPUT: ADMNO ENROLLNO COURS YEARSEM ADATE CNAME
--------- --------- ----- -------------- --------- -------------333 111 222 103 BCA-IIA III 101 BCA-IIA I 102 BCA-IIA II 01-JAN-08 Surya College 01-JAN-09 Christ College 01-JAN-10 PG College
(e)(c)List the students in the session who are not in the colleges in the same city they live in. QUERIES: SQL> SELECT NAME,ENROLLMENT.ADDRESS,COLLEGES.CNAME,CITY FROM COLLEGES,ENROLLMENT,ADMISSION WHERE ADMISSION.CNAME=COLLEGES.CNAME AND ENROLLMENT.ENROLLNO=ADMISSION.ADMNO AND COLLEGES.CITY!='Jagdalpur';
OUTPUT:
NAME
ADDRESS
CNAME
CITY
------------ ------------------ ------------------------- -----------Ankit Krishna Jenny Priyanka Freezerpur MATS College Raipur Bhilai Bhilai Raipur
Vindravan Coloney Rungta College Awintika Coloney Shankrachayar College aasna Disha College
(e)(d)List the students in colleges in your city and also live in your city.
QUERIES:
pg. 72
DBMS practical
SQL> SELECT NAME,ENROLLMENT.ADDRESS,COLLEGES.CNAME,CITY FROM COLLEGES,ENROLLMENT,ADMISSION WHERE ADMISSION.CNAME=COLLEGES.CNAME AND ENROLLMENT.ENROLLNO=ADMISSION.ADMNO AND COLLEGES.CITY='Jagdalpur' AND ENROLLMENT.ADDRESS LIKE '%Geedam Road';
OUTPUT:
NAME
ADDRESS
CNAME
CITY
QUESTION 3
Subjects (paperid, subject, paper, papername) Test (paperid, date, time, max, min) Score (rollno, paperid, marks, attendance) Students (admno, rollno, class, yearsem)
a: - Create the above tables with the given specifications and constraints. b: - Insert about 10 rows as are appropriate to solve the following queries.
SUBJECT TABLE
QUERIES:
Table created.
pg. 73
DBMS practical
QUERIES:
SQL> INSERT INTO SUBJECTS VALUES('&PAPERID','&SUBJECT','&PAPERNO','&PAPERNAME'); Enter value for paperid: 1 Enter value for subject: MATHS Enter value for paperno: II Enter value for papername: A-700 OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM SUBJECTS; OUTPUT: PAPERID SUBJECT PAPER PAPERNAME
--------- ---------------- ----- --------1 2 3 4 5 6 7 8 9 10 MATHS C++ POM II A-700 III C-700 I J-700 III L-700
NETWORKING LINUX
II M-700
DATA STRUCTURE II Q-700 ENGLISH HINDI MATHS-II DBMS I I I III S-700 T-700 Y-700 Z-700
pg. 74
TEST TABLE
QUERIES: SQL> CREATE TABLE TEST(PAPERID VARCHAR(9), TDATE DATE, TIME VARCHAR(10), MAX VARCHAR(10), MIN VARCHAR(10), PRIMARY KEY(PAPERID)); OUTPUT: Table created. QUERIES: SQL> INSERT INTO TEST VALUES('&PAPERID','&TDATE','&TIME','&MAX','&MIN'); Enter value for paperid: 1 Enter value for tdate: 03-MAR-08 Enter value for time: 09:00 AM Enter value for max: 100 Enter value for min: 40 OUTPUT: 1 row created. QUERIES: SQL> SELECT * FROM TEST; OUTPUT: PAPERID TDATE TIME MAX MIN
--------- --------- ---------- ---------- ---------1 2 3 03-MAR-08 09:00 AM 100 06-MAR-08 09:00 AM 100 07-MAR-08 09:00 AM 100 40 40 40
pg. 75
DBMS practical 4 5 6 7 8 9 10 09-MAR-08 09:00 AM 100 12-MAR-08 09:00 AM 100 15-MAR-08 09:00 AM 100 18-MAR-08 09:00 AM 100 21-MAR-08 09:00 AM 100 24-MAR-08 09:00 AM 100 28-MAR-08 09:00 AM 100 40 40 40 40 40 40 40
10 rows selected.
SCORE TABLE
QUERIES: SQL> CREATE TABLE SCORE(ROLLNO NUMBER(5), PAPERID VARCHAR(5), MARKS NUMBER(5), ATTENDENCE VARCHAR(10), PRIMARY KEY(ROLLNO)); OUTPUT: Table created. QUERIES: SQL> INSERT INTO SCORE VALUES(&ROLLNO,'&PAPERID',&MARKS,'&ATTENDENCE'); Enter value for rollno: 1 Enter value for paperid: 1 Enter value for marks: 90 Enter value for attendence: PRESENT OUTPUT: 1 row created.
pg. 76
DBMS practical QUERIES: SQL> SELECT * FROM SCORE; OUTPUT: ROLLNO PAPER MARKS ATTENDENCE
--------- ----- --------- ---------11 22 33 44 55 66 77 88 99 10 10 90 PRESENT 80 PRESENT 80 PRESENT 50 PRESENT 0 ABSENT 39 PRESENT 40 PRESENT 60 PRESENT 85 PRESENT 0 ABSENT
10 rows selected.
STUDENTS TABLE
QUERIES: SQL> CREATE TABLE STUDENTS (ADMNO NUMBER(5), ROLLNO NUMBER(5), CLASS VARCHAR(5), YEARSEM VARCHAR(5),PRIMARY KEY(ADMNO)); OUTPUT: Table created. QUERIES:
pg. 77
DBMS practical
SQL> INSERT INTO STUDENTS VALUES(&ADMNO,&ROLLNO,'&CLASS','&YEARSEM'); Enter value for admno: 111 Enter value for rollno: 1 Enter value for class: BCA-IIA Enter value for yearsem: I OUTPUT: INSERT INTO STUDENTS VALUES(&ADMNO,&ROLLNO,'&CLASS','&YEARSEM') INSERT INTO STUDENTS VALUES(222,2,'BCA-IIA','II'); 1 row created.
QUERIES: SQL> SELECT * FROM STUDENTS; OUTPUT: ADMNO ROLLNO CLASS YEARS --------- --------- ----- ----111 222 333 444 555 666 777 888 999 1 BCA-IIA I 2 BCA-IIA II 3 BCA-IIA III 4 BCA-IIOM I 5 BCA-IIOM II 6 BCA-IIOM III 7 BSC I 8 BSC III 9 BSC II
pg. 78
10 rows selected.
Que c: - List the students who were present in a paper of a subject. QUERIES: SQL>SELECT STUDENTS.ROLLNO, SUBJECTS.PAPERID, SUBJECTS.SUBJECT, SCORE.ATTENDENCE FROM SUBJECTS, SCORE, STUDENTS WHERE SUBJECTS.PAPERID = SCORE.PAPERID AND STUDENTS.ROLLNO = SCORE.ROLLNO AND SCORE.ATTENDENCE = 'PRESENT'; OUTPUT: ROLLNO PAPERID SUBJECT --------- --------- ---------------- ---------11 22 33 44 66 77 88 99 MATHS C++ POM PRESENT PRESENT PRESENT PRESENT ATTENDENCE
NETWORKING
8 rows selected. Que d:- List all roll numbers who have passed in 1st division. QUERIES: SQL>SELECT STUDENTS.ROLLNO, STUDENTS.CLASS, STUDENTS.YEARSEM, SUBJECTS.PAPERID, SUBJECTS.SUBJECT, SCORE.MARKS FROM SUBJECTS, SCORE, STUDENTS
pg. 79
DBMS practical
WHERE SUBJECTS.PAPERID = SCORE.PAPERID AND STUDENTS.ROLLNO = SCORE.ROLLNO AND SCORE.MARKS >= '60'; OUTPUT: ROLLNO CLASS YEARS PAPERID SUBJECT --------- ----- ----- --------- ---------------- --------1 BCA-IIA I 1 MATHS C++ POM HINDI MATHS-II 60 85 90 80 80 MARKS
Que e: - List all students in BCA-IIA-II who have scored higher than average. (i)
QUERIES:
In your college.
OUTPUT:
ROLLNO --------2
MARKS --------80
Que f: - List the highest score, average and minimum score in BCA-IIA-II.
(i) In your college.
pg. 80
DBMS practical
QUERIES:
SQL> SELECT MAX(SCORE.MARKS) "HIGHEST SCORE", AVG(SCORE.MARKS) "AVERAGE SCORE", MIN(SCORE.MARKS) "MINIMUM SCORE" FROM SCORE, STUDENTS WHERE STUDENTS.ROLLNO = SCORE.ROLLNO AND STUDENTS.CLASS='BCA-IIA' AND STUDENTS.YEARSEM= 'II';
OUTPUT: HIGHEST SCORE ------------80 AVERAGE SCORE ------------80 MINIMUM SCORE ------------80
pg. 81
DBMS practical
1] Print the name of the employees with the manager name using cursor?
SQL> set serveroutput on; SQL> declare 2 cursor name is 3 select * from employees; 4 i employees%rowtype; 5 begin 6 open name;
pg. 82
DBMS practical 7 dbms_output.put_line('ename'||' '||'manager'); 8 loop 9 fetch name into i; 10 exit when name%notfound; 11 dbms_output.put_line(i.ename ||' '|| i.manager); 12 end loop; 13 close name; 14 end; 15 /
OUTPUT: ename Rahul Priyanka Sohan Ved manager Mohit Isha Mohan Rupesh
Atif Meenakshi
pg. 83
Q.2 Print Fibonacci series? 1 declare 2 a number; 3 b number; 4 c number; 5 i number; 6 n number; 7 begin
pg. 84
DBMS practical 8 a:=0; 9 b:=1; 10 n:= & terms; 11 dbms_output.put_line(a); 12 dbms_output.put_line(b); 13 for i in 1..n 14 loop 15 c:=a+b; 16 dbms_output.put_line(c); 17 a:=b; 18 b:=c; 19 end loop; 20* end; SQL> /
OUTPUT: Ente r value for terms: 3 old 10: n:= & terms; new 10: n:= 3; 0 1 1 2
pg. 85
pg. 86
DBMS practical 8 for a in 1..b 9 loop 10 fact:= fact*a; 11 end loop; 12 dbms_output.put_line('factorial of' ||' '||b||' is'||' '||fact); 13* end; SQL> /
Q.4 Update the salary of employees by 25% if the salary > 3000 else update the salary to 3000.
1 declare 2 cursor salary1 is 3 select * from employees; 4 i employees%rowtype; 5 begin 6 open salary1; 7 loop
pg. 87
DBMS practical 8 fetch salary1 into i; 9 exit when salary1%notfound; 10 if i.salary>3000 then
11 update employees set salary=i.salary+25*i.salary where salary>3000 ; 12 elsif i.salary<3000 then 13 update employees set salary=3000 where salary<3000; 14 dbms_output.put_line(i.ename ||' '|| i.salary); 15 end if; 16 end loop; 17 close salary1; 18* end; SQL> / OUTPUT: Nitesh 1200 PL/SQL procedure successfully completed.
pg. 88
DBMS practical 9 loop 10 K:=mod(n,i); 11 if k=0 then 12 j:=i; 13 exit; 14 end if; 15 end loop; 16 if n=j then 17 dbms_output.put_line('prime'); 18 else 19 dbms_output.put_line('not prime'); 20 end if; 21 end; 22 /
OUTPUT:
pg. 89
DBMS practical
pg. 90