You are on page 1of 5

M.

Chinyuku Database Systems 2023

MySQL Practical 3- Update Table


(CRUD)
CRUD stands for
• Create or Insert record (s) in a table

• Read or retrieve record (s) from a table

• Update or Modify record (s) in a table

• Delete record (s) in a table

1. Create database Exercise2

CREATE DATABASE Exercise2;

2. Create the following tables using SQL scripts

Customer
Customer Customer Name Customer Address
Number
1000 James 1-2nd Ave
1111 Mary 3235 Mukwati street
1100 John 1-2nd Ave

Orders
Order Number Order Date Customer Number
a123 16 October 2021 1000
a220 27 September 1100
2022
a233 27 September 1100
2022

Marks
Student Number Student Name Quiz 1 Quiz 2
S105666 Mary 45 60
S100001 John 87 40
S105000 James 50 50

a. Customer(cnum, cname, cadd)

Page 1|5
M. Chinyuku Database Systems 2023

b. Orders(onum, odate,cnum)

c. Marks(snum, sname, quiz1, quiz2)

3. Insert into the customer table the following record (1001, John, Nguruve st)
Insert record – Syntax
INSERT INTO table_name (

field1, field2,...fieldN )
VALUES ( value1, value2,...valueN );

String values are enclosed in single or double quotes

4. Change order date of order number “a123” to 10 September 2017

Page 2|5
M. Chinyuku Database Systems 2023

UPDATE record Syntax


UPDATE table_name
SET column1  =  value1,  column2  =  value2, ...
WHERE condition;

5. Delete all students with marks less than 50 for quiz 1

DELETE Syntax
DELETE FROM table_name [WHERE Condition];

Activity
In a college database. A lecturer can teach up to a maximum of 3 courses. Every lecturer must have a
course to teach. For every lecturer, employee id, name and the office is recorded. A course
may be offered in a semester or not at all. A course is defined by its course id, course name
and the department name to which it belongs. Each class is described by a unique classId,
day, times and venue.

1. Develop a conceptual model for the scenario

2. Translate the conceptual model above to sets of relational schemas

Lecturer (LecturerID, LecturerName, Office)


Course (CourseID, CourseName, Department)
Class (ClassID, LecturerID, CourseID, Venue, Time, Day)

Page 3|5
M. Chinyuku Database Systems 2023

3. Implement the relational schemas using MySQL

CREATE DATABASE exercise 3;

CREATE table Lecturer (


LecturerID varchar(5),
LecturerName varchar(25),
Office char(5),
PRIMARY KEY (LecturerID)
);

CREATE TABLE Course (


CourseID char(10),
CourseName varchar(25),
Department varchar (25),
PRIMARY KEY (CourseID)
);

CREATE TABLE Class(


ClassID char(5),
LecturerID varchar (5),
CourseID char (10),
Day varchar (15),
Time time,
venue varchar (10),
PRIMARY KEY (classID),
Constraint FOREIGN key (LecturerID) REFERENCES Lecturer(LecturerID),
CONSTRAINT FOREIGN KEY (CourseID) REFERENCES Course(CourseID)
ON DELETE CASCADE
ON UPDATE CASCADE
);

4. Populate the tables with the given information

LECTURER Table
LecturerID LecturerNam Office
e
E1001 Chinyuku E7
E1002 Kavu E8
E1003 Rugube E10

Page 4|5
M. Chinyuku Database Systems 2023

E1004 Phiri E8
E1005 Moyo E26

COURSE Table
CourseID CourseName Department
CUIT201 Database ICT
CUMT10 OR Maths
5
CUIT206 OOP ICT
CUIT208 Software Eng ICT
CUPE105 Logic Design Engineering
CUIT213 Data Comm Engineering
CUEB401 Database Business

CLASS Table
ClassI LecturerI CourseID Day Time Venu
D
C1001 E1002 CUIT206 Monday 0800 Tlab
C1002 E1001 CUIT201 Monday 1000 Tlab
C1003 E1005 CUPE105 Wednesday 1400 NEC2
C1005 E1004 CUMT105 Friday 1200 NEC3

5. Write SQL scripts to:

a. Insert a new lecturer record with the following details (E1010, Moyo, E30)

b. Modify Class table such that all lectures on Monday are shifted to Friday

c. Delete all courses with name Database from course table

Page 5|5

You might also like