Databse programming Assignement
Databse programming Assignement
RegNumber: 223010386
Class: Computer Science II
Date: 19 March 2025
In my commands you will see comments begin with -- as my MySQL version allowed me to use
● SQL Stored Procedures
These are my tables in cs2db database
DELIMETER ;;
CREATE PROCEDURE UpdatePhone()
BEGIN
UPDATE student
SET phone = '0123456789'
WHERE ID = parm;
END
DELIMETER;
A corresponding image
● SQL Functions
This function displays all tables in database
BEGIN
DECLARE table_count INT;
RETURN table_count;
END
This function displays current time.
BEGIN
RETURN NOW();
END
DELIMITER $$
DELIMITER ;
Result of executing violating the rules
● SQL Cursors
This cursor adds a word verified to people names with phone number length greater or
equal to 10.
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE student_id INT;
OPEN cur;
read_loop: LOOP
-- Fetch a student ID
FETCH cur INTO student_id;
CLOSE cur;
END
● SQL Assertions
This Assertion is used to prevent inserting Age below 18. Down Is the result ot tring to
violate this rule in my database.
Here is the next result when users try to update their Age below 18
● SQL Views
This creates a view all tables in my database
CREATE VIEW student_supervisors AS
SELECT
s.ID AS student_id,
s.Fname AS student_name,
l.lecturer AS supervisor_name
FROM student s
JOIN lecturers l ON s.ID = l.ID;