MySql Exercise 2 - Update Records
MySql Exercise 2 - Update Records
Update Table
CRUD
CRUD
• C-Create or Insert a record
• R- Read or retrieve a record
• U- Update or Modify a record
• D-Delete a record
Exercise
1. Create database Exercise2
2. Create the following tables
a) Customer(cnum, cname, cadd)
b) Orders(onum, odate,cnum)
c) Marks(snum, sname, quiz1, quiz2)
3. Insert into the customer table the following record
(1001, John, Nguruve st)
4. Update the record in orders table by changing the
order date of a record.
5. Delete all students with marks less than 50 for quiz 1
1. Create database Exercise2
CREATE DATABASE Exercise2;
2a) Create table from the relational
schema:
Customer(cnum, cname, cadd)
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
4. Update the record in orders table by
changing the order date of a record.
UPDATE orders
SET odate = '2017-09-10'
WHERE onum = 'a123';
DELETE Syntax
CLASS
ClassID LecturerID CourseID Day Time Venue
C1001 E1002 CUIT206 Monday 0800 Tlab
C1002 E1001 CUIT201 Monday 1000 Tlab
C1003 E1005 CUPE105 Wednesday 1400 NEC2
C1005 E1004 CUMT105 Friday 1200 NEC3
Lecturer table
CREATE TABLE Lecturer (
LecturerID CHAR(5),
LecturerName VARCHAR(25),
Office CHAR(5),
PRIMARY KEY (LecturerID)
);
Course Table
CREATE TABLE Course(
CourseID Char(10),
CourseName VARCHAR(25),
Department VARCHAR (25),
PRIMARY KEY (CourseID)
);
Class Table
Create TABLE Class(
ClassID char(5),
LecturerID Char(5),
CourseID CHAR(10),
DAY VARCHAR(15),
Time TIME,
Venue VARCHAR (10),
FOREIGN KEY(LecturerID) REFERENCES lecturer(LecturerID),
FOREIGN KEY (CourseID) REFERENCES course(CourseID)
ON DELETE CASCADE
);
• Write SQL scripts to:
1. Insert a record for a new lecturer
(E1010, Moyo, E30)
2. Modify Class table such that you move all
lectures on Monday to Friday
3. Delete all courses with name Database from
course table
Insert
1. Insert a record for a new lecturer
(E1010, Moyo, E30)
UPDATE Class
SET Day = 'Friday'
WHERE Day = 'Monday';
• Delete all courses with name Database from course
table
DELETE FROM course
WHERE CourseName='Database';