0% found this document useful (0 votes)
202 views86 pages

DATABASE Report

dbms

Uploaded by

rihanna kasula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
202 views86 pages

DATABASE Report

dbms

Uploaded by

rihanna kasula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 86

TRIBHUVAN UNIVERSITY

BHAKTAPUR MULTIPLE CAMPUS


DUDHPATI, BHAKTAPUR

A PRACTICAL LAB REPORT

OF

DATABASE MANAGEMENT SYSTEM

Submitted by:

Rihana Kasula

Section: Lily

Submitted to:

Milan Chikanbanjar

Bhaktapur Multiple Campus

(In the partial fulfillment of the requirement for the course

Database Management System 2023/24)


CERTIFICATE

This is certified to be the record of work done by Mr. /Miss ………………………


in Database Management System of BHAKTAPUR MULTIPLE CAMPUS in the
Department of Database Management System during year 2023 A.D.

NAME: Rihana Kasula COURSE: BBA

SYMBOL NO: SEMESTER: SECOND

……………………………………

(MILAN CHIKANBANJAR)

Department of Database Management System

Submitted for the practical examination held on …………………………..

2
EVALUATION SHEET

We have concluded the viva voice examination of the Lab Report presented by
………………………….. and found the record to be the original work and according to
the prescribed format of Database Management System.

----------------------------- ----------------------------

(Internal evaluator) (External evaluator)

3
Rihana Kasula

1. Show all databases.

Syntax:

 Show databases;

Output:

2. Create a database staff, colz and dept.

Syntax:

 Create database staff;


Show databases;
 Create database colz;
Show databases;
 Create database dept;
Show databases;

Output:

4
Rihana Kasula

3. Drop database staff and colz.


Syntax:
 Drop database staff;
Show databases;
 Drop database colz;
Show databases;

Output:

4. Create a table employee in dept database with following columns:

EmpID Integer Not Null


LastName Varchar Not Null
FirstName Varchar Not Null
Gender Varchar Not Null
Title Varchar Not Null
Syntax:
 Use dept;
 Create table employee
(
empid int(5) not null,
lastname varchar(25) not null,
firstname varchar(25) not null,
gender varchar (10) not null,
title varchar(20) not null
);
Show tables;

5
Rihana Kasula

Describe employee;

Output:

5. Create table student (roll int) and post (id int).

Syntax:

 Create table student


(
roll int(5)
);
Show tables;
Describe student;

Output:

6
Rihana Kasula

 Create table post


(
Id int(5)
);
Show tables;
Describe post;

Output:

6. Drop table student and post.

Syntax:

 Drop table student;


Show tables;
 Drop table post;
Show tables;

Output:

7
Rihana Kasula

7. Create database Multiple.

Syntax:

 Create database multiple;


Show databases;
Output:

8. Create table Student(roll_no-primary key, name-unique, address, gender-not


null, age(>18 and <35)).

Syntax:

 Use multiple;
 Create table student
(
roll_no int(5) primary key,
name varchar(25) unique,
address varchar(40),
gender varchar(10) not null,
age int(5),
check (age>18 and age<35)
);
Show tables;
Describe student;
Output:

8
Rihana Kasula

9. Create table class (room_no-Primary key, no_bench-not null).

Syntax:

 Create table class


(
room_no int(5) primary key,
no_bench int(5) not null,
);
Show tables;
Describe class;
Output:

9
Rihana Kasula

10. Drop table class.

Syntax:

 Drop table class;


Show tables;

Output:

11. Rename table student into studentinfo.

Syntax:

 Alter table student


Rename to studentinfo;
Output:

12. Create table client (id – primary key, name, address).

Syntax:

 Create table client


(
id int(5) primary key,
name varchar(25),
address varchar(40)

10
Rihana Kasula

);
Describe client;
Output:

13. Add a column named Age of datatype integer and size 3 in the client table.

Syntax:

 Alter table client


Add column age int(3);
Describe client;
Output:

14. Add a column named Phone of datatype integer and size 10 in the client table.

Syntax:

 Alter table client


Add column phone int(10);
Describe client;
Output

11
Rihana Kasula

15. Add a column named email of datatype varchar and size 20 in the client table
immediately after the column Name.

Syntax:

 Alter table client


Add column email varchar(20) after name;
Describe client;

16. Add a column named registration no of datatype integer and size 20 in client
table immediately after id.

Syntax:

 Alter table client


Add column registration int(20) after id;
Describe client;
Output:

12
Rihana Kasula

17. Add a column named country of datatype varchar and size 15 in the client
table as the first column.
Syntax:
 Alter table client
Add column country varchar(15) first;
Describe client;
Output:

18. Drop the column phone from the client table.


Syntax:
 Alter table client
Drop column phone;
Describe client;
Output:

13
Rihana Kasula

19. Modify the size of the column email to 25 in the client table.
Syntax:
 Alter table client
Modify column email varchar(25);
Describe client;
Output:

20. Change the column name Age to CntAge in the client table.
Syntax:
 Alter table client
Rename column age to cntage;
Describe client;
Output:

21. Change the column address to location in the client table and shift it
immediate after the column name.
Syntax:
 Alter table client
Rename column address to location;
 Alter table client

14
Rihana Kasula

Modify column location varchar(25) after name;


Output:

22. Create table employee(eno-primary key, ename-unique, salary, post).


Syntax:
 Create table employee
(
eno int(5) primary key,
ename varchar(25) unique,
salary int(10),
post varchar(40)
);
Show tables;
Describe employee;
Output:

15
Rihana Kasula

23. Create table books as described below:

Field Data Type Constraint Type


BookID Integer PRIMARY KEY
BookName Varchar NOT NULL
Author Varchar UNIQUE
Price integer CHECK price>500
Syntax:
 Create table books
(
bookid int(5) primary key,
bookname varchar(40) not null,
author varchar(25) unique,
price int(10),
CHECK (price>500)
);
Show tables;
Describe books;
Output:

16
Rihana Kasula

24. Create table customer as described below:

Field Data Type Constraint Type


CustID Integer PRIMARY KEY
CustName Varchar NOT NULL
Email Varchar UNIQUE
IssueDate date
BookID integer FOREIGN KEY
Syntax:
 Create table customer
(
Custid int(10) primary key,
Custname varchar(25) not null,
Email varchar(25) unique,
Issuedate date,
Bookid int(5),
FOREIGN KEY(bookid) REFERENCES books(bookid)
);
Show tables;
Describe customer;
Output:

17
Rihana Kasula

25. Create table teacher as described below:

Field Data Type Constraint Type

TID Integer PRIMARY KEY

TName Varchar NOT NULL

Address Varchar

Salary integer NOT NULL

Syntax:
 Create table teacher
(
tid int(5) primary key,
tname varchar(25) not null,
address varchar(40),
salary int(10) not null
);
Show tables;
Describe teacher;
Output:

18
Rihana Kasula

26. Create table student as described below:

Field Data Type Constraint Type

SID Integer PRIMARY KEY

SName Varchar NOT NULL

Age Integer

DateOfBirth date

Phone Integer UNIQUE

TID integer FOREIGN KEY

Syntax:

 Create table student


(
sid int(5) primary key,
sname varchar (25) not null,
age int(5),
dateofbirth date,
phone int(10) unique,
tid int(5),
FOREIGN KEY(tid) REFERENCES teacher(tid)
);
Show tables;
Describe student;
Output:

19
Rihana Kasula

27. Write SQL statement to add a new column ‘address’ in student table after
SName.
Syntax:
 Alter table student
Add column address varchar(40) after sname;
Describe student;
Output:

28. Write SQL statement to add a new column ‘RollNo’ in student table at first
and ‘Fee’ after Phone.
Syntax:
 Alter table student
Add column rollno int(5) first,
Add column fee int(10) after phone;
Describe student;
Output:

29. Write SQL statement to drop a column ‘address’ in student table.


Syntax:
 Alter table student
Drop column address;
Describe student;

20
Rihana Kasula

Output:

30. Write SQL statement to modify the size of column ‘SName’ in student table
to varchar(50).
Syntax:
 Alter table student
Modify column sname varchar(50);
Describe student;
Output:

31. Write SQL statement to change the constraint type of column ‘RollNo’ from
NULL to NOT NULL and modify Fee data type from int to varchar in student
table.
Syntax:
 Alter table student
Modify column rollno int(5) not null,
Modify column fee varchar(25);
Describe student;
Output:

21
Rihana Kasula

32. Write SQL statement to rename column Phone to ContactNo in student table.
Syntax:
 Alter table student
Rename column phone to contactno;
Describe student;
Output:

33. Use dept database. Insert 10 rows into employee table as shown below:

EmpID LastName FirstName Gender Title


1000 Thapa Yogita Female Programmer
1001 Khanal John Male Programmer
1002 Gautam Lisa Female President
1003 Chhetri Jeni Female Programmer
1005 Shrestha Matina Male Accountant
1006 K. C. Chetana Female Designer
1010 Shrestha Ram Male Programmer
1011 Nath Robin Male Programmer
1012 Shrestha Ludan Male Technician
1013 Pradhan Dinesh Male Designer
Syntax:
 Use dept;
 Insert into employee (empid, lastname, firstname, gender, title) values
(1000,’Thapa’,’Yogita’,’Female’,’Programmer’),

22
Rihana Kasula

(1001,’Khanal’,’John’,’Male’,’Programmer’),

(1002,’Gautam’,’Lisa’,’Female’,’President’),
(1003,’Chhetri’,’Jeni’,’Female’,’Programmer’),
(1005,’Shrestha’,’Matina’,’Male’,’Accountant’),
(1006,’K.C.’,’Chetana’,’Female’,’Designer’),
(1010,’Shrestha’,’Ram’,’Male’,’Programmer’),
(1011,’Nath’,’Robin’,’Male’,’Programmer’),
(1012,’Shrestha’,’Ludan’,’Male’,’Technician’),
(1013,’Pradhan’,’Dinesh’,’Male’,’Designer’)
;
Select * from employee;
Output:

34. Update the title of Jeni to QA.


Syntax:
 Update employee set title=’QA’ where firstname=’Jeni’;
Select * from employee;
Output:

23
Rihana Kasula

35. Update the Female gender to ‘F’.


Syntax:
 Update employee set gender=’f’ where gender=’female’;
Select * from employee;
Output:

36. Update the gender Male to ‘M’.


Syntax:
 Update employee set gender=’m’ where gender=’male’;
Select * from employee;

24
Rihana Kasula

Output:

37. Delete the record of employee whose title is QA.


Syntax:
 Delete from employee where title=’QA’;
Select * from employee;
Output:

38. Delete the record of President title.


Syntax:
 Delete from employee where title=’president’;
Select * from employee;
Output:

25
Rihana Kasula

39. Use multiple database. Insert 5 rows into the table studentinfo.
Syntax:
 Use multiple;
 Insert into studentinfo (roll_no,name,address,gender,age) values (1,’Ram
Thapa’,’Bhaktapur’,’Male’,20),
(2,’Sita Sharma’,’Kathmandu’,’Female’,21),
(3,’Rakesh Shrestha’,’Lalitpur’,’Male’,22),
(4,’Supriya Shyama’,’Dharan’,’Female’,23),
(5,’Hari Duwal’,’Kavre’,’Male’,24);

Select * from studentinfo;

Output:

40. Delete row having age 20.


Syntax:

26
Rihana Kasula

 Delete from studentinfo where age=20;

Select * from studentinfo;


Output:

41. Update rows having age 21 to 23.


Syntax:
 Update studentinfo set age=23 where age=21;
Select * from studentinfo;
Output:

42. Insert 3 rows in teacher table.


Syntax:
 Insert into teacher (tid,tname,address,salary) values (101,’Milan
Chikanbanjar’,’Bhaktapur’,10000),
(102,’Suman Thapa’,’Kathmandu’,20000),
(103,’Reshma Rai’,’Lalitpur’,30000);
Select * from teacher;
Output:

27
Rihana Kasula

43. Delete all rows of teacher table.


Syntax:
 Delete from teacher;
Select * from teacher;
Output:

44. Insert 2 rows into client.


Syntax:
 Insert into client (country,id,registration,name,location,email,cntage)
values (‘Nepal’,1,1001,’Ram Thapa’,’Bhaktapur’,’[email protected]’,25),
(‘India’,2,1002,’Sita Kurunju’,’Kathmandu’,’[email protected]’30);
Select * from client;
Output:

45. Delete/truncate all rows of client.


Syntax:
 Delete from client;

28
Rihana Kasula

Select * from client;


Output:

46. Insert 4 rows in the employee table.


Syntax:
 Insert into employee (eno,ename,salary,post) values (1,’Ramesh
Koju’,20000,’Manager’),
(2,’Siru Thapa’,10000,’Secretary’),
(3,’Riya Kumar’,25000,’Director’),
(4,’Ajit Duwal’,30000,’Chairman’);
Select * from employee;
Output:

47. Update the salary of employee with 20%.


Syntax:
 Update employee set salary=salary*1.2;
Select * from employee;
Output:

29
Rihana Kasula

48. Create database bktA/bktB and use it.

Syntax:

 Create database bktA;


Use bktA;
Output:

49. Create the following tables.

Department

Field Data Type Constraint Type

ID Number(4) Primary Key

Name Varchar(25) NOT NULL

BlockNo Number(4)

Student

Field Data Type Constraint Type

Sid Number(4) Primary Key

Sname Varchar(25) NOT NULL

Saddress Varchar(25)

Age Number(4)

DID Number(4) Foreign Key

Syntax:

30
Rihana Kasula

 Create table department


(
did int(4) primary key,
name varchar(25) not null,
blockno int(4)
);
Describe department;
 Create table student
(
sid int(4) primary key,
sname varchar(25) not null,
saddress varchar(25),
age int(4),
did int(4),
FOREIGN KEY (did) REFERENCES department(did)
);
Show tables;
Describe student;
Output:

31
Rihana Kasula

50. Insert following data in following tables

Department

ID Name BlockNo

1 Computer 100

2 Mathematics 200

3 Economics 300

4 Account 400

Student

Sid Sname Saddress Age DID

10 Maya Palpa 21 1

11 Abin Ktm 22 2

12 Aarav Ktm 19 1

13 Ashna Palpa 33 3

14 Anuj Pokhara 23 4

15 Manish Banepa 22 2

16 Pinky Ktm 43 1

Syntax:

 Insert into department (did,name,blockno) values (1,’Computer’,100),


(2,’Mathematics’,200),
(3,’Economics’,300),
(4,’Account’,400);
Select * from department;

32
Rihana Kasula

 Insert into student (sid,sname,saddress,age,did)


values(10,’Maya’,’Palpa’,21,1),
(11,’Abin’,’Ktm’,22,2),
(12,’Aarav’,’Ktm’,19,1),
(13,’Ashna’,’Palpa’33,3),
(14,’Anuj’,’Pokhara’,23,4),
(15,’Manish’,’Banepa’,22,2),
(16,’Pinky’,’Ktm’,43,1);
Select * from student;
Output:

33
Rihana Kasula

51. Find unique address of student.

Syntax:

 Select distinct saddress from student;

Output:

52. Find name, department id and age of all student whose address is not ‘ktm’.

Syntax:

 Select sname,did,age from student


Where saddress notlike ‘ktm’;

Output:

34
Rihana Kasula

53. Change address of all student whose age is less than 25 to ‘Bhaktapur’.

Syntax:

 Update student set address=’bhaktapur’ where age<25;


Select * from student;

Output:

54. Update name of student to ‘Punty’ and address to ‘Lalitpur’ whose age is
greater than 35 and id also greater than 15.

Syntax:

 Update student set sname=’Punty’,saddress=’lalitpur’


where age>35 and sid>15;
Select * from student;

Output:

35
Rihana Kasula

55. Delete the record of the student ‘Anuj’.

Syntax:

 Delete from student where name=’anuj’;


Select * from student;

Output:

56. Delete the record of the student whose age is greater than 35.

Syntax:

 Delete from student where age>35;


Select * from student;

Output:

36
Rihana Kasula

57. Delete the student whose address is ‘Palpa’ and age greater than 30.

Syntax:

 Delete from student where saddress=’palpa’ and age>30;


Select * from student;

Output:

58. Find name, address and department id of those student whose department id is
1.

Syntax:

 Select sname,saddress,did from student where did=1;

Output:

37
Rihana Kasula

59. Find id and name of all student whose name contains the characters ’a’ and ‘n’
in the name.

Syntax:

 Select sid,sname from student where sname like ‘%a%n%’;

Output:

60. Find id and name of the student whose name start with letter ‘a’.

Syntax:

 Select sid,sname from student where name like ‘a%’;

Output:

38
Rihana Kasula

61. Find name, address and age of the student whose age is in the range of 20 to
30.

Syntax:

 Select sname,,saddress,age from student where age between 20 and 30;

Output:

62. Find id, name and department id of student whose department id is not
between 2 and 4.

Syntax:

 Select sid,sname,did from student where did not between 2 and 4;

Output:

63. Find name of those department whose block number is greater than 200.

Syntax:

 Select name from department where blockno>200;

Output:

39
Rihana Kasula

64. Find name and block number of department of name as ‘Computer’,


‘Account’, ‘Physics’ or ‘English’.

Syntax:

 Select name,blockno from department where name in


(‘Computer’,’Account’,’Physics’,’English’);

Output:

65. Find name of department in descending order.

Syntax:

 Select name from department order by name desc;

Output:

40
Rihana Kasula

66. Use sakila.

Syntax:

 Use sakila;

Output:

67. Show tables in sakila database.

Syntax:

 Show tables;

Output:

41
Rihana Kasula

68. Display all records of country.

Syntax:

 Select * from country;

Output:

69. Display all 8 records of country table.

Syntax:

 Select * from country limit 8;

Output:

42
Rihana Kasula

70. Display 5 records having country_id and country from the table of country.

Syntax:

 Select country_id,country from country limit 5;

Output:

71. Display 10 records of country from country table.

Syntax:

 Select country from country limit 10;

Output:

72. List out all country whose country_id less than 7.

Syntax:

43
Rihana Kasula

 Select country from country where country_id<7;

Output:

73. List out all country whose country_id greater than 105.

Syntax:

 Select country from country where country_id>105;

Output:

74. Display records having country_id and country from the table of country
whose country_id less than 9.

Syntax:

 Select country_id,country from country where country_id<9;

Output:

44
Rihana Kasula

75. Display records having country from the table of country whose country_id
greater than 102.

Syntax:

 Select country from country where country_id>102;

Output:

76. Use world;

Syntax:

 Use world;

45
Rihana Kasula

Output:

77. Display all information of country.

Syntax:

Select * from country;

Output:

78. Display name, code, continent and surfacearea top 3 rows of country table.

Syntax:

 Select name,code,continent,surfacearea from country limit 3;

Output:

79. Display name, code, continent and surfacearea top 10 rows of country table.

Syntax:
46
Rihana Kasula

 Select name,code,continent,surfacearea from country limit 10;

Output:

80. Display name, code, and surfacearea from country table whose continent is
Asia.

Syntax:

 Select name,code,surfacearea from country where continent=’Asia’;

Output:

81. Display name, code, continent and surfacearea from country table whose
surfacearea is greater than 1000000.

Syntax:

47
Rihana Kasula

 Select name,code,continent,surfacearea from country where


surfacearea>1000000;

Output:

82. List name of country where the second character in its name is ‘e’.

Syntax:

 Select name from country where name like ‘_e%’;

Output:

83. List name of country where the third character in its name is ‘p’.

Syntax:

 Select name from country where name like ‘__p%’;

Output:

48
Rihana Kasula

84. List top 10 name of country where the last characters in its name is not ‘an’.

Syntax:

 Select name from country where name not lke ‘%an’ limit 10;

Output:

85. List top 15 name of country where the third character in its name has either ‘e’
or ‘p’.

Syntax:

 Select name from country where name like ‘__e%’ or name like ‘__p%’
limit 15;

Output:

49
Rihana Kasula

86. List name and continent from country whose country name has four
characters.

Ans:

 Select name,continent from country where name like ‘____’;

Syntax:

87. List name and continent from country whose country name has four characters
and the last character is ‘n’.

Syntax:

 Select name,continent from country where name like ‘___n’;

Output:

50
Rihana Kasula

88. List name and continent from country whose country name has four characters
whose first character starts with ‘p’ and the last character ends with ‘u’.

Syntax:

 Select name,continent from country where name like ‘p__u’;

Output:

89. Use world;

Syntax:

 Use world;

Output:

90. List name and continent from country whose country name has third character
‘p’ having five character in total.

Syntax:

 Select name,continent from country where name like ‘__p__’;

Output:

51
Rihana Kasula

91. Display name and surfacearea of countrywhose surfacearea lies between 400
and 600.

Syntax:

 Select name,surfacearea from country where surfacearea between 400 and


600;

Output:

92. Display name and surfacearea of country whose surfacearea lies in 200, 260
and 344.

Syntax:

 Select name,surfacearea from country where surfacearea in (200,260,344);

Output:

93. Display name and population of country whose population ranges from
100000000 to 10000000000.

52
Rihana Kasula

Syntax:

 Select name,population from country where population between


100000000 and 10000000000;

Output:

94. Display name, code, continent and surfacearea of country with surfacearea lies
between 2000000 to 5000000.

Syntax:

 Select name,code,continent,surfacearea from country where surfacearea


between 2000000 and 5000000;

Output:

95. List name and continent from country that lies in Asia, Africa and Antarctica
displaying 5 rows.

53
Rihana Kasula

Syntax:

 Select name,continent from country where continent in


(‘Asia’,’Africa’,’Antarctica’) limit 5;

Output:

96. List name and continent from country that does not lie in Asia, Africa,
Europe, South America and Antarctica displaying 10 rows.

Syntax:

 Select name,continent from country where continent not in


(‘Asia’,’Africa’,’Europe’,’South America’,’Antarctica’) limit 10;

Output:

54
Rihana Kasula

97. List name and continent from country whose continentletter starts with E, S
and N characters displaying 10 rows.

Syntax:

 Select name,continent from country where continent like ‘E%’ or


continent like ‘S%’ or continent like ‘N%’ limit 10;

Output:

98. Use Sakila.

Syntax:

 Use sakila;

Output:

99. List all the actor whose first_name starts with A, J, or M displaying 10 rows.

Syntax:

 Select * from actor where first_name like ‘a%’ or first_name like ‘j%’ or
first_name like ‘m%’;

Output:

55
Rihana Kasula

100. Find actor_id, first_name and last_name from actor whose actor_id lies
between 110 to 125.

Syntax:

 Select actor_id,first_name,last_name from actor where actor_id between


110 and 125;

Output:

101. Find actor_id, first_name and last_name from actor whose actor_id lies in2,
45, 79, 157, 160, 179, 190, and 200.

Syntax:

 Select actor_id,first_name,last_name from actor where actor_id in


(2,45,79,157,160,179,190,200);

Output:

56
Rihana Kasula

102. Find actor_id, first_name and last_name from actor whoselast_namestarts


with ‘j’ and the last character ends with ‘a’ or ‘e’.

Syntax:

 Select actor_id,first_name,last_name from actor where last_name like ‘j


%a’ or last_name like ‘j%e’;

Output:

103. Find actor_id, first_name and last_name from actor whose first_name has
third character ‘l’ having five character in total.

Syntax:

 Select actor_id,first_name,last_name from actor where first_name like


‘__l__’;

Output:

57
Rihana Kasula

104. Find film_id, title and rating of film whose rating is G or PG displaying 10
rows.

Syntax:

 Select film_id,title,rating from film where rating like ‘G’ or rating like
‘PG’ limit 10;

Output:

105. Find film_id, title and rating of film whosefilm_id ranges from 900 to 970
displaying 15 rows.

Syntax:

 Select film_id,title,rating from film where film_id between 900 and 970
limit 15;

Output:

106. Find film_id, title and rating of film whose film_id is 134, 245, 368, 413,
579, 632, 700, 831.

Syntax:

 Select film_id,title,rating from film where film_id in


(134,245,368,413,579,632,700,831);

58
Rihana Kasula

Output:

107. Find FID, title, category and rating of film_list whose price is more than
equals to 2.

Syntax:

 Select FID,title,category,rating from film_list where price>=2 limit 10;

Output:

108. Find FID, title, category and rating of film_list whose category is action or
horror or comedy.

Syntax:

 Select FID,title,category,rating from film_list where category in


(‘actor’,’horror’,’comedy’)limit 10;

Output:

59
Rihana Kasula

109. Find FID, title, category and rating of film_list whose category is sci-fi.

Syntax:

 Select FID,title,category,rating from film_list where category=’sci-fi’


limit 10;

Output:

110. Find FID, title, category and rating of film_list whose rating is R and price is
less than 3.

Syntax:

 Select FID,title,category,rating from film_list where rating=’R’ and price<3


limit 10;

Output:

60
Rihana Kasula

111. List all distinct category of film_list.

Syntax:

 Select distinct category from film_list;

Output:

112. List all distinct staff_id of payment table.

Syntax:

 Select distinct staff_id from payment;

Output:

61
Rihana Kasula

113. Find all payment_id, rental_id, amount and staff_id of payment table whose
customer_id is 55.

Syntax:

 Select payment_id,rental_id,amount,staff_id from payment where


customer_id=55;

Output:

114. Find all payment_id, rental_id, amount and staff_id of payment table whose
customer_id is 123, 234, 345, 456, and 567.

Syntax:

 Select payment_id,rental_id,amount,staff_id from payment where


customer_id in (123,234,345,456,567) limit 10;

Output:

62
Rihana Kasula

115. Find all payment_id, rental_id, amount and staff_id of payment with
payment_id in the range 15000 to 15050.

Syntax:

 Select payment_id,rental_id,amount,staff_id from payment where


payment_id between 15000 and 15050 limit 10;

Output:

116. List out the amount of customer_id 420 in payment table.

Syntax:

 Select amount from payment where customer_id=420;

Output:

63
Rihana Kasula

117. Find FID, title, category and rating of film_list whose category has three
characters.

Syntax:

 Select FID,title,category,rating from film_list where category like ‘___’ limit


10;

Output:

118. Find FID, title, category and rating of film_list whose category starts with T,
the third character is A and the last character is L.

Syntax:

 Select FID,title,category,rating from film_list where category like ‘T_A%L’


limit 10;

Output:

64
Rihana Kasula

119. Find distinct store_id of customer.

Syntax:

 Select distinct store_id from customer;

Output:

120. Find the category_id and name of category whose category_id is 6, 9, 12 and
15.

Syntax:

 Select category_id,name from category where category_id in (6,9,12,15);

Output:

121. Create table MStud with following values:

bid boyname

1 Ajay

2 Bijay

3 Chandan

65
Rihana Kasula

bid boyname

4 Dijen

Syntax:

 Create table MStudA


(
bid int(15),
boyname varchar(25)
);
Describe MStudA;
 Insert into MStudA (bid,boyname) values (1,’Ajay’),
(2,’Bijay’),
(3,’Chandan’),
(4,’Dijen’);
Select * from MStudA;

Output:

122. Create table FStudA with following values:

gi
girlname

1 Alisha

66
Rihana Kasula

gi
girlname

2 Basanti

5 Emma

6 Shova

Syntax:

 Create table FStudA


(
gid int(5),
girlname varchar(25)
);
Describe FStudA;
 Insert into FStudA (gid,girlname) values (1,’Alisha’),
(2,’Basanti’),
(3,’Emma’),
(4.’Shova’);
Select * from FStudA;

Output:

123. Use Inner Join for tables MStudA and FStudA.

67
Rihana Kasula

Syntax:

 Select * from MStudA inner join FStudA on bid=gid;

Output:

124. Use Left Join for tables MStudA and FStudA.

Syntax:

 Select * from MStudA left join FStudA on bid=gid;

Output:

125. Use Right Join for tables MStudA and FStudA.

Syntax:

 Select * from MStudA right join FStudA on bid=gid;

Output:

126. Use Full Join for tables MStudA and FStudA.

Syntax:

 Select * from MStudA left join FStudA on bid=gid


Union
Select * from MStudA right join FStudA on bid=gid;

68
Rihana Kasula

Output:

Aggregate functions:

Min(), Max(), Avg(), Count(), Sum()

127. USE world,

Syntax:

 Use world;

Output:

128. Display average gnp from country whose continent is Asia.

Syntax:

 Select avg(gnp) from country where continent=’Asia’;

Output:

129. Display average capital from country whose continent is Europe.

Syntax:

 Select avg(capital) from country where continent=’Europe’;

69
Rihana Kasula

Output:

130. Display name of country which has maximum population.

Syntax:

 Select name from country where population=(select max(population) from


country);

Output:

131. Display maximum capital from country and find the name of country having
maximum capital.

Syntax:

 Select max(capital) from country ;select name from country where


capital=(select max(capital) from country);

Output:

132. Display name of country which has minimum population.

Syntax:

 Select name from country where population=(select min(population) from


country);

Output:

70
Rihana Kasula

133. Display name of country which has minimum gnp.

Syntax:

 Select name from country where gnp=(select min(gnp) from country);

Output:

134. Count the number of country which has population more than 1,00,00,000.

71
Rihana Kasula

Syntax:

 Select count(population) from country where population>10000000;

Output:

135. Count the number of country and use alias as “Number” which has
population more than 20,00,00,000.

Syntax:

 Select count(population) as number from country where


population>200000000;

Output:

136. Find the total surfacearea of Asia.

Syntax:

 Select sum(surfacearea) from country where continent=’Asia’;

Output:

137. Find total gnp of Africa.

Syntax:

 Select sum(gnp) from country where continent=’Africa’;

72
Rihana Kasula

Output:

Multiple SELECT statements

138. Use World.

Syntax:

 Use world;

Output:

139. Display all details from city table whose name starts with N and end with d
followed by name, code, continent from country table whose country name is
Nepal.

Syntax:

 Select * from city where name like’N%D’;select name,code,continent


from country where name=’Nepal’;

Output:

73
Rihana Kasula

140. Display all details from city table whose name starts with ‘A’ and end with
‘d’ followed by name, code, continent from country table whose country name
is Nepal and again followed by all details from country language whose
language is Nepali.

Syntax:

 Select * from city where name like ‘A%D’ ; select name,code,continent


from country where name=’Nepal’; select * from countrylanguage where
language=’Nepali’;

Output:

141. Use bktA/bktB.

74
Rihana Kasula

Syntax:

 Use bktA;

Output:

142. Create the following tables in the database.

StudentDetails

SID Name Address

1 Harsh Kathmandu

2 Ashish Dharan

3 Pratik Dhankuta

4 Dhanraj Bhaktapur

5 Ram Pokhara

StudentMarks

I Name Address Marks Age


D
1 Harsh Kathmandu 90 19
2 Ashish Dharan 50 20
3 Pratik Dhankuta 80 19
4 Dhanraj Bhaktapur 95 21
6 Suresh Pokhara 85 22

Syntax:

 Create table studentdetails


(

75
Rihana Kasula

sid int(3),
name varchar(25),
address varchar(30)
);
Describe studentdetails;
Insert into studentdetails (sid,name,address) values
(1,’harsh’,’kathmandu’),

(2,’ashish’,’dharan’),
(3,’pratik’,’dhankuta’),
(4,’dhanraj’,’bhaktapur’),
(5,’ram’,’pokhara’);
Select * from studentdetails;

Output:

 Create table studentmarks


(
id int(5),
name varchar(25),
address varchar(25),
marks int(5),
age int(5)
);
Describe studentmarks;
Insert into studentmarks (id,name,address,marks,age) values
(1,’harsh’,’kathmandu’,90,19),
(2,’ashish’,’dharan’,50,20),
76
Rihana Kasula

(3,’pratik’,’dhankuta’,80,19),
(4,’dhanraj’,’bhaktapur’,95,21),
(5,’ram’,’pokhara’,85,22);
Select * from studentmarks;

Output:

143.Create a view named DetailsView from the table StudentDetails containing


name, address and SID less than 5.

Syntax:

 Create view detailsview as select name,address from studentdetails where


sid<5;

Output:

ut:

144. Display all information of DetailsView.

Syntax:

 Select * from detailsview;

Output:

77
Rihana Kasula

145.Create a view named StudentNames from the table StudentDetails with SID,
Name order by name.

Syntax:

 Create view studentnames as select sid,name from studentdetails order by


name;

Output:

146. Display all information of StudentNames.

Syntax:

 Select * from studentnames;

Output:

147. Create a view named MarksView from the tables StudentDetails and
StudentMarks containing SID, Name, Address, Marks whose names are same
in both tables.

Syntax:

78
Rihana Kasula

 Create view marksview as select d.sid,d.name,d.address.m.marks from


studentdetails as d,studentmarks as m where d.name=m.name;

Output:

148. Display all information of MarksView.

Syntax:

 Select * from marksview;

Output:

149. Create a view named AgeView from the table StudentMarks containing
Name and Age.

Syntax:

 Create view ageview as select name,age from studentmarks;

Output:

150. Display all information of AgeView.

Syntax:

 Select * from ageview;

Output:

79
Rihana Kasula

151. Update the age of Suresh to 18 in AgeView.

Syntax:

 Update ageview set age=18 where name=’Suresh’;

Output:

152. Display all information of AgeView and StudentMarks.

Syntax:

 Select * from ageview; select * from studentmarks;

Output:

80
Rihana Kasula

153. INSERT a row in DetailsView with VALUES (“Suresh”, “Gurgaon”);

Syntax:

 Insert into detailsview (name,address) values (‘Suresh’,’Gurgaon’);

Output:

154. Insert a row in DetailsView with VALUES (“Diksha”, “Biratnagar”).

Syntax:

 Insert into detailsview (name,address) values (‘Diksha’,’Biratnagar’);


Select * from detailsview;

Output:

155. Display all information of DetailsView and StudentDetails.

Syntax:

 Select * from detailsview; select * from studentdetails;

81
Rihana Kasula

Output:

156. Delete the record of Suresh from AgeView.

Syntax:

 Delete from ageview where name=’Suresh’;


Select * from ageview;

Output:

157. Display all information of AgeView and StudentMarks.

Syntax:

 Select * from ageview; select * from studentmarks;

Output:

82
Rihana Kasula

158. Create a view StudentM from StudentMarks containing ID, Name, Address.

Syntax:

 Create view studentM as select id,name,address from studentmarks;

Output:

159. Display all records from the tables StudentDetails and StudentM using
UNION.

Syntax:

 Select * from studentdetails


Union

83
Rihana Kasula

Select * from studentM;

Output:

160. Display all records from the tables StudentDetails and StudentM using
UNION ALL.

Syntax:

 Select * from studentdetails


Union all
Select * from studentM;

Output:

161.Drop the view MarksView.

Syntax:

 Drop view marksview;


Select * from marksview;

Output:

84
Rihana Kasula

162. Delete all records of AgeView and drop it.

Syntax:

 Delete from ageview;drop view ageview;


 Show tables;
 Select * from ageview;

Output:

85
Rihana Kasula

86

You might also like