Database Management System
Database Management System
BY
Sleshma Thapa
T.U.Reg No.7-2-361-56-2022
Submitted to
Universal College
Maitidevi, Kathmandu
Certificate
This is to certify that Sleshma Thapa, student of BBA(2nd semester) of symbol number 36283/22 has successfully completed her lab
assignment on Database Management System in the practical examination. It is further certified that this project is the individual work of
the candidate.
Date: 2080/
Signature: Signature:
Acknowledgement
This report has been prepared as partial requirement for the internal evaluation of Bachelor of Business Administration (BBA). It is great
opportunity for me to be part of this project.
I would like to thank my teacher Mr. Hem Sagar Pokhrel for helping me on this project. He allowed me to work on this project . Along with
that, I would also like to thank my college whole heartedly. I would also want to thank my friends who helped me in finalizing this project
within a limited time frame.
CONTENTS
Task 1 .....................................................................................................................................
Task 2 .....................................................................................................................................
Task 3 .....................................................................................................................................
Output:
2. Insert record in it
- INSERT INTO student VALUES(05,'sleshma','Graduate',19,'female');
Output:
3. Display all records
- SELECT * FROM student ;
Output:
4. Add new column contact no
Output:
Output:
5. Remove column level
Output:
6. Add new column level
Output:
- DESC student ;
Output:
8. Put the values in contact no [ due to limited byte real values cannot be display so modify the datatype integer into varchar (15) ]
- UPDATE student
- UPDATE student
- WHERE sid= 01 ;
Output:
9. Insert four more records and delete the record of Thor who left the college recently
Output:
Output:
10. Delete all records
Output:
12. create the table Student ( sid , sname , level, age , sex )
Age <= 20
Output:
Lab Assignment 2
Task 1
Student (sid,sname,age,sex)
Output:
Enrollby ( sid,cid )
Taghtby ( iid,cid )
- CREATE table instructor ( iid integer PRIMARY KEY, iname varchar (15) , age integer,sex varchar(15));
- CREATE table course (cid varchar(6) PRIMARY KEY ,cname varchar (15), credithours integer);
- CREATE TABLE enrollby (sid integer, cid varchar(6), FOREIGN KEY(sid) REFERENCES student(sid), FOREIGN KEY(cid) REFERENCES
course(cid));
- CREATE table taughtby (iid integer , cid varchar(6) , FOREIGN KEY (iid) REFERENCES instructor (iid), FOREIGN KEY (cid) REFERENCES
course(cid));
Output:
Task 2
- INSERTINTOStudent VALUES(101,’sleshma’,’graduate’,20,’female’),(106,’silu’,’graduate’,20,’female’),
(107,’anamika’,’graduate’,20,’female’);
Output:
Output:
- INSERT into enrollby VALUES (101,301),(102,302),(103,303),(104,305),(105,304);
Output:
Task 3
Output:
2. Print or Display or Find all the records of the instructor.
Output:
3. Print or Display or Find all the records of the course.
Output:
4. Find the name and level of the female student over the age 22.
Output:
5. Find the name of instructor whose age is less than 28.
Output:
6. Find id, name, level and age of student by increasing age by 1.
- FROM student;
Output:
7. List the name of the instructors whose age is greater than 30 .
Output:
8. Find the name of student who study SAD.
- SELECT sname FROM student NATURAL JOIN course NATURAL JOIN enrollby
Output:
9. Find the name and age of those students whose age is greater than 25 and sex is male.
Output:
- UPDATE course
Output:
11. Display the name of those students whose level is unknown.
Output:
12. List the students who are not enrolled in any courses.(hint: Select* from student natural join enrolled by natural join course where cid is
NULL).
- SELECT * FROM student NATURAL JOIN enrollby NATURAL JOIN course where cid is null ;
Output:
Output:
14. Update the level of student Sita with postgraduate.
Output:
Output:
16. Find iname of all instructors whose name contains ‘an’ somewhere.
Output:
17. Find name and level of students whose age is between 20 and 25.
- SELECT sname, level FROM student WHERE age>20 AND age <25;
Output:
18. How many students are taking course of 3 credit hours .
Output:
19. Find id and name of all instructors in the order of sex and then in descending order of age.
20. Find id and name of all undergraduate students in ascending order of name .
- SELECT sid, sname FROM student WHERE LEVEL = 'undergraduate' ORDER BY sname ASC;
Output:
21. Find record of all courses taught by instructor 302.
Output:
- SELECT sid, sname FROM student NATURAL JOIN course NATURAL JOIN enrollby WHERE cname='BBA';
Output:
23. Find id,name , level of all students whose age is greater than at least one student.
- SELECT sid,sname,level
- FROM student
Output:
Output:
26. Display the name of instructor with maximum age.
- SELECT iname
Output:
27. Find name of courses taught by each male instructors.
Output:
28. Find average age for all levels of student that have average age more than 20.
- SELECT LEVEL , AVG (age) AS average_age FROM student GROUP BY LEVEL HAVING AVG (age)>20;
Output:
29. Add new column ‘addresses’ to student table.
Output:
30. Remove column ‘addresses’ from student table.
Output:
31. Modify student relation by changing data type of sname to varchar(30).
Output:
32. Create view that contains id, name, level of those students whose age is greater than 24.
- CREATE VIEW student .view AS SELECT sid, sname , level FROM student WHERE age > 24;
Output:
33. Remove the view table just created.
Output:
Lab Assignment 3
1. Find ID and name of all females who are instructor or student. Also identify the different between
- SELECT sid AS id , sname AS name FROM student WHERE sex ='female' UNION ALL
- SELECT iid AS id, iname as name FROM instructor WHERE sex ='female'
Output:
2. Find ID , name and age of all persons who are instructors as well as student .
3. Find ID , name and age of all persons who are instructors but not student.
Output:
4. Find the average age for all levels of students .
Output:
5. Find average age for all levels of students that have average age more than 22.
- SELECT level , AVG (age) AS average_age FROM student GROUP BY level HAVING AVG (age)>22;
Output:
6. Select the name of instructor who teaches computer science , and whose names are neither raja or ram.
- SELECT iname FROM instructor NATURAL JOIN taughtby NATURAL JOIN course WHERE cname ='computer science' AND iname NOT IN
('raja','ram');
Output:
7. Find ID , name and age of all instructor whose age is greater than age of all students.
Output:
8. Increase credit hour of courses by 5 whose credit hour is more than 3 otherwise increase credit hour by 1.
- UPDATE course SET credithours= CASE WHEN credithours >3 THEN credithours+5 ELSE credithours +1 END ;
Output: