DATABASE Report
DATABASE Report
OF
Submitted by:
Rihana Kasula
Section: Lily
Submitted to:
Milan Chikanbanjar
……………………………………
(MILAN CHIKANBANJAR)
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.
----------------------------- ----------------------------
3
Rihana Kasula
Syntax:
Show databases;
Output:
Syntax:
Output:
4
Rihana Kasula
Output:
5
Rihana Kasula
Describe employee;
Output:
Syntax:
Output:
6
Rihana Kasula
Output:
Syntax:
Output:
7
Rihana Kasula
Syntax:
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
Syntax:
9
Rihana Kasula
Syntax:
Output:
Syntax:
Syntax:
10
Rihana Kasula
);
Describe client;
Output:
13. Add a column named Age of datatype integer and size 3 in the client table.
Syntax:
14. Add a column named Phone of datatype integer and size 10 in the client table.
Syntax:
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:
16. Add a column named registration no of datatype integer and size 20 in client
table immediately after id.
Syntax:
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:
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
15
Rihana Kasula
16
Rihana Kasula
17
Rihana Kasula
Address Varchar
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
Age Integer
DateOfBirth date
Syntax:
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:
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:
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:
23
Rihana Kasula
24
Rihana Kasula
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);
Output:
26
Rihana Kasula
27
Rihana Kasula
28
Rihana Kasula
29
Rihana Kasula
Syntax:
Department
BlockNo Number(4)
Student
Saddress Varchar(25)
Age Number(4)
Syntax:
30
Rihana Kasula
31
Rihana Kasula
Department
ID Name BlockNo
1 Computer 100
2 Mathematics 200
3 Economics 300
4 Account 400
Student
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:
32
Rihana Kasula
33
Rihana Kasula
Syntax:
Output:
52. Find name, department id and age of all student whose address is not ‘ktm’.
Syntax:
Output:
34
Rihana Kasula
53. Change address of all student whose age is less than 25 to ‘Bhaktapur’.
Syntax:
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:
Output:
35
Rihana Kasula
Syntax:
Output:
56. Delete the record of the student whose age is greater than 35.
Syntax:
Output:
36
Rihana Kasula
57. Delete the student whose address is ‘Palpa’ and age greater than 30.
Syntax:
Output:
58. Find name, address and department id of those student whose department id is
1.
Syntax:
Output:
37
Rihana Kasula
59. Find id and name of all student whose name contains the characters ’a’ and ‘n’
in the name.
Syntax:
Output:
60. Find id and name of the student whose name start with letter ‘a’.
Syntax:
Output:
38
Rihana Kasula
61. Find name, address and age of the student whose age is in the range of 20 to
30.
Syntax:
Output:
62. Find id, name and department id of student whose department id is not
between 2 and 4.
Syntax:
Output:
63. Find name of those department whose block number is greater than 200.
Syntax:
Output:
39
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
40
Rihana Kasula
Syntax:
Use sakila;
Output:
Syntax:
Show tables;
Output:
41
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
42
Rihana Kasula
70. Display 5 records having country_id and country from the table of country.
Syntax:
Output:
Syntax:
Output:
Syntax:
43
Rihana Kasula
Output:
73. List out all country whose country_id greater than 105.
Syntax:
Output:
74. Display records having country_id and country from the table of country
whose country_id less than 9.
Syntax:
Output:
44
Rihana Kasula
75. Display records having country from the table of country whose country_id
greater than 102.
Syntax:
Output:
Syntax:
Use world;
45
Rihana Kasula
Output:
Syntax:
Output:
78. Display name, code, continent and surfacearea top 3 rows of country table.
Syntax:
Output:
79. Display name, code, continent and surfacearea top 10 rows of country table.
Syntax:
46
Rihana Kasula
Output:
80. Display name, code, and surfacearea from country table whose continent is
Asia.
Syntax:
Output:
81. Display name, code, continent and surfacearea from country table whose
surfacearea is greater than 1000000.
Syntax:
47
Rihana Kasula
Output:
82. List name of country where the second character in its name is ‘e’.
Syntax:
Output:
83. List name of country where the third character in its name is ‘p’.
Syntax:
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:
Syntax:
87. List name and continent from country whose country name has four characters
and the last character is ‘n’.
Syntax:
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:
Output:
Syntax:
Use world;
Output:
90. List name and continent from country whose country name has third character
‘p’ having five character in total.
Syntax:
Output:
51
Rihana Kasula
91. Display name and surfacearea of countrywhose surfacearea lies between 400
and 600.
Syntax:
Output:
92. Display name and surfacearea of country whose surfacearea lies in 200, 260
and 344.
Syntax:
Output:
93. Display name and population of country whose population ranges from
100000000 to 10000000000.
52
Rihana Kasula
Syntax:
Output:
94. Display name, code, continent and surfacearea of country with surfacearea lies
between 2000000 to 5000000.
Syntax:
Output:
95. List name and continent from country that lies in Asia, Africa and Antarctica
displaying 5 rows.
53
Rihana Kasula
Syntax:
Output:
96. List name and continent from country that does not lie in Asia, Africa,
Europe, South America and Antarctica displaying 10 rows.
Syntax:
Output:
54
Rihana Kasula
97. List name and continent from country whose continentletter starts with E, S
and N characters displaying 10 rows.
Syntax:
Output:
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:
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:
Output:
56
Rihana Kasula
Syntax:
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:
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:
58
Rihana Kasula
Output:
107. Find FID, title, category and rating of film_list whose price is more than
equals to 2.
Syntax:
Output:
108. Find FID, title, category and rating of film_list whose category is action or
horror or comedy.
Syntax:
Output:
59
Rihana Kasula
109. Find FID, title, category and rating of film_list whose category is sci-fi.
Syntax:
Output:
110. Find FID, title, category and rating of film_list whose rating is R and price is
less than 3.
Syntax:
Output:
60
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
61
Rihana Kasula
113. Find all payment_id, rental_id, amount and staff_id of payment table whose
customer_id is 55.
Syntax:
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:
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:
Output:
Syntax:
Output:
63
Rihana Kasula
117. Find FID, title, category and rating of film_list whose category has three
characters.
Syntax:
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:
Output:
64
Rihana Kasula
Syntax:
Output:
120. Find the category_id and name of category whose category_id is 6, 9, 12 and
15.
Syntax:
Output:
bid boyname
1 Ajay
2 Bijay
3 Chandan
65
Rihana Kasula
bid boyname
4 Dijen
Syntax:
Output:
gi
girlname
1 Alisha
66
Rihana Kasula
gi
girlname
2 Basanti
5 Emma
6 Shova
Syntax:
Output:
67
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
Syntax:
Output:
Syntax:
68
Rihana Kasula
Output:
Aggregate functions:
Syntax:
Use world;
Output:
Syntax:
Output:
Syntax:
69
Rihana Kasula
Output:
Syntax:
Output:
131. Display maximum capital from country and find the name of country having
maximum capital.
Syntax:
Output:
Syntax:
Output:
70
Rihana Kasula
Syntax:
Output:
134. Count the number of country which has population more than 1,00,00,000.
71
Rihana Kasula
Syntax:
Output:
135. Count the number of country and use alias as “Number” which has
population more than 20,00,00,000.
Syntax:
Output:
Syntax:
Output:
Syntax:
72
Rihana Kasula
Output:
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:
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:
Output:
74
Rihana Kasula
Syntax:
Use bktA;
Output:
StudentDetails
1 Harsh Kathmandu
2 Ashish Dharan
3 Pratik Dhankuta
4 Dhanraj Bhaktapur
5 Ram Pokhara
StudentMarks
Syntax:
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:
(3,’pratik’,’dhankuta’,80,19),
(4,’dhanraj’,’bhaktapur’,95,21),
(5,’ram’,’pokhara’,85,22);
Select * from studentmarks;
Output:
Syntax:
Output:
ut:
Syntax:
Output:
77
Rihana Kasula
145.Create a view named StudentNames from the table StudentDetails with SID,
Name order by name.
Syntax:
Output:
Syntax:
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
Output:
Syntax:
Output:
149. Create a view named AgeView from the table StudentMarks containing
Name and Age.
Syntax:
Output:
Syntax:
Output:
79
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
80
Rihana Kasula
Syntax:
Output:
Syntax:
Output:
Syntax:
81
Rihana Kasula
Output:
Syntax:
Output:
Syntax:
Output:
82
Rihana Kasula
158. Create a view StudentM from StudentMarks containing ID, Name, Address.
Syntax:
Output:
159. Display all records from the tables StudentDetails and StudentM using
UNION.
Syntax:
83
Rihana Kasula
Output:
160. Display all records from the tables StudentDetails and StudentM using
UNION ALL.
Syntax:
Output:
Syntax:
Output:
84
Rihana Kasula
Syntax:
Output:
85
Rihana Kasula
86