Show databases;
mysql> create database studentTutorial;
Query OK, 1 row affected (5.87 sec)
mysql> use studentTutorial;
Database changed
Show tables;
(1) Create the following tables which contain the following associated fields.
Student (SID char(5),RollNo char(10),SName char(30),Year char(20))
Subject (SubId char(5), SubName char(30), SubCode char(10), Year char(20),
TeacherName char(30))
Tutorial (Tid char(5), ExamDate Date, TutorialName char(20), SID char(5),
SubId char(5), GivenMark int, ReceivedMark int)
mysql> create table student(sid char(5),rollno char(10),sname char(30),year
char(20),primary key(sid));
Query OK, 0 rows affected (3.96 sec)
mysql> create table subject(subid char(5),subname char(30),subcode char(10),year
char(20),teachername char(30),primary key(subid));
Query OK, 0 rows affected (0.37 sec)
mysql> create table tutorial(tid char(5),examdate date,tutorialname char(20),sid
char(5),subid char(5),givenmark int,receivemark int,primary
key(tid,sid,subid),foreign key(sid) references student(sid),foreign key(subid)
references suject(subid));
Query OK, 0 rows affected (0.77 sec)
(2) Fill the following data into the tables.
Student
SID RollNo SName Year
1CST-
S1 Su Su First Year
1
1CST-
S2 Mg Mg First Year
2
Aung Second
S3 2CS-1
Aung Year
Second
S4 2CS-2 Moe Moe
Year
Second
S5 2CT-1 Yadanar
Year
mysql> insert into student values('s1','1cst-1','su su','first year');
Query OK, 1 row affected (0.29 sec)
mysql> insert into student values('s2','1cst-2','mg mg','first year');
1 of 1
Query OK, 1 row affected (0.07 sec)
mysql> insert into student values('s3','2cs-1','aung aung','second year');
Query OK, 1 row affected (0.05 sec)
mysql> insert into student values('s4','2cs-2','moe moe','second year');
Query OK, 1 row affected (0.05 sec)
mysql> insert into student values('s5','2ct-1','yadanar','second year');
Query OK, 1 row affected (0.04 sec)
Select * from Student;
Subject
SubI
SubName SubCode Year TeacherName
D
CST-
Sub1 Principle of IT First Year Daw Phyu Phyu
1111
CST-
Sub2 Mathematics First Year Daw Mya Mya
1142
CST- Second
Sub3 Learn to Java Daw Win Moe
2111 Year
CST- Second
Sub4 Mathematics Daw Mya Mya
2142 Year
CST- Second
Sub5 Digital Daw Thazin
2133 Year
mysql> insert into subject values('sub1','principle of IT','cst-1111','second
year','Daw phyu phyu');
Query OK, 1 row affected (0.10 sec)
mysql> insert into subject values('sub2','Mathematics','cst-1142','first
year','Daw mya mya');
Query OK, 1 row affected (0.07 sec)
mysql> insert into subject values('sub3','learn to java','cst-2111','second
year','Daw win moe');
Query OK, 1 row affected (0.06 sec)
mysql> insert into subject values('sub4','Mathematics','cst-2142','second
year','Daw mya mya');
Query OK, 1 row affected (0.07 sec)
mysql> insert into subject values('sub5','digital','cst-2133','second year','Daw
thazin');
Query OK, 1 row affected (0.04 sec)
2 of 1
Select * from Subject;
Tutorial
Ti ExamDate TutorialNa SI SubID GivenMa ReceivedMar
d me D rk k
T1 2024/2/2 Tutorial-I S1 Sub1 50 45
T2 2024/3/2 Tutorial-I S2 Sub2 50 40
T3 2024/2/2 Tutorial-I S3 Sub3 50 40
T4 2024/5/2 Tutorial-I S3 Sub4 50 48
T5 2024/3/2 Tutorial-I S4 Sub4 50 38
T6 2024/2/5 Tutorial-I S5 Sub5 50 46
mysql> insert into tutorial values('t1','2024/2/2','tutorial-I','s1','sub1',50,45);
Query OK, 1 row affected, 1 warning (0.92 sec)
mysql> insert into tutorial values('t2','2024/3/2','tutorial-I','s2','sub2',50,40);
Query OK, 1 row affected, 1 warning (0.14 sec)
mysql> insert into tutorial values('t3','2024/2/2','tutorial-I','s3','sub4',50,40);
Query OK, 1 row affected, 1 warning (0.09 sec)
mysql> insert into tutorial values('t4','2024/5/2','tutorial-I','s4','sub4',50,48);
Query OK, 1 row affected, 1 warning (0.05 sec)
mysql> insert into tutorial values('t5','2024/3/2','tutorial-I','s4','sub4',50,38);
Query OK, 1 row affected, 1 warning (0.05 sec)
mysql> insert into tutorial values('t6','2024/2/5','tutorial-I','s4','sub5',50,46);
Query OK, 1 row affected, 1 warning (0.07 sec)
Select * from Tutorial;
Write MySQL statements for the following problems using the tables created in (1).
(3) Change the teacher name to ‘U Kyaw’ of subject id ‘Sub2’.
mysql> update subject set teachername ='U Kyaw' where subid='sub2';
Query OK, 1 row affected (0.19 sec)
Rows matched: 1 Changed: 1 Warnings: 0
(4) Get the names of the subject and the student who gained less than 45 marks.
mysql> select subname from subject,tutorial where subject.subid=tutorial.subid
and receivemark < 45;
+-------------+
| subname |
+-------------+
3 of 1
| Mathematics |
| Mathematics |
| Mathematics |
+-------------+
(5) Retrieve all information of student whose name starts with ‘M’.
mysql> select * from student where sname like 'M%';
+-----+--------+---------+-------------+
| sid | rollno | sname | year |
+-----+--------+---------+-------------+
| s2 | 1cst-2 | mg mg | first year |
| s4 | 2cs-2 | moe moe | second year |
+-----+--------+---------+-------------+
2 rows in set (0.00 sec)
(6) Get tutorial name, roll numbers and received marks which the exam-date
is‘2024/3/2’.
mysql> select tutorialname,rollno,receivemark from tutorial,student where
student.sid=tutorial.sid and examdate='2024/3/2';
+--------------+--------+-------------+
| tutorialname | rollno | receivemark |
+--------------+--------+-------------+
| tutorial-I | 1cst-2 | 40 |
| tutorial-I | 2cs-2 | 38 |
+--------------+--------+-------------+
2 rows in set, 1 warning (0.10 sec)
(7) Get the details of subjects that is taught in first year.
mysql> select subject.* from subject where year='first year';
+-------+-----------------+----------+------------+---------------+
| subid | subname | subcode | year | teachername |
+-------+-----------------+----------+------------+---------------+
| sub1 | principle of IT | cst-1111 | first year | Daw phyu phyu |
| sub2 | Mathematics | cst-1142 | first year | U Kyaw |
+-------+-----------------+----------+------------+---------------+
2 rows in set (0.05 sec)
(8) Display different year and subject code from the schema subject where subject
name is in descending order.
mysql> select year,subcode,subname from subject order by subname desc;
+-------------+----------+-----------------+
| year | subcode | subname |
+-------------+----------+-----------------+
| first year | cst-1111 | principle of IT |
| first year | cst-1142 | Mathematics |
| second year | cst-2142 | Mathematics |
4 of 1
| second year | cst-2111 | learn to java |
| second year | cst-2133 | digital |
+-------------+----------+-----------------+
5 rows in set (1.64 sec)
(9) Find the name of subject which include the substring ‘them’ student.
mysql> select subid,subname from subject where subname like '%them%';
+-------+-------------+
| subid | subname |
+-------+-------------+
| sub2 | Mathematics |
| sub4 | Mathematics |
+-------+-------------+
2 rows in set (0.10 sec)
(10) Find name of student whose roll no contains character ‘T’ in their names
third position.
mysql> select distinct sname from student where rollno like '__t%';
+---------+
| sname |
+---------+
| yadanar |
+---------+
(11) Delete all student information of student id 5.
mysql> delete from student where sid = 's5';
Query OK, 1 row affected (0.80 sec)
(12) Create the view and its name is Student_Information to find the highest
received mark of student whose name is ‘Aung Aung’.
mysql> create view student_name_order as select student.* from student order by
sname;
Query OK, 0 rows affected (1.43 sec)
5 of 1