DB_PUVM_System

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

/*

Accounts and User info tables

(Acc_id, Acc_Username, Acc_password, Acc_Fullname)

(User_id, User_Fullname, User_Firstname, User_Midname, User_Lastname, User_Suffix, User_age,


Acc_gender, Acc_Birtdate)

(User_id, User_Fullname, User_phonenum, Acc_Email)

(User_id, User_Fullname, User_Housenum, User_street, User_brgy, User_Municaplity, User_province)

*/

create database if not exists DB_PUVM_System;

-- Create the accounts table

CREATE TABLE IF NOT EXISTS tbl_accounts (

Acc_id INT AUTO_INCREMENT PRIMARY KEY,

Acc_Username Varchar(255) not null,

Acc_password VARCHAR(255) NOT NULL,

Acc_Status VARCHAR(25) NOT NULL,

FOREIGN KEY (Acc_id) REFERENCES tbl_user_profile(User_id) ON DELETE CASCADE

);

select*from tbl_accounts;

-- Create the user profile table

CREATE TABLE IF NOT EXISTS tbl_user_profile (

User_id INT AUTO_INCREMENT PRIMARY KEY,

User_Fullname VARCHAR(100),

User_Firstname VARCHAR(50) NOT NULL,

User_Midname VARCHAR(50),

User_Lastname VARCHAR(50) NOT NULL,

User_Suffix VARCHAR(10),

User_age INT NOT NULL,


Acc_gender VARCHAR(10) NOT NULL,

Acc_Birthdate DATE NOT NULL,

User_type VARCHAR(50) not null

);

-- Create the user contact table

CREATE TABLE IF NOT EXISTS tbl_user_contact (

User_id INT AUTO_INCREMENT PRIMARY KEY,

User_phonenum VARCHAR(15) UNIQUE,

Acc_Email VARCHAR(100) UNIQUE,

FOREIGN KEY (User_id) REFERENCES tbl_user_profile(User_id) ON DELETE CASCADE

);

-- Create the user address table

CREATE TABLE IF NOT EXISTS tbl_user_address (

User_id INT AUTO_INCREMENT PRIMARY KEY,

User_Housenum VARCHAR(10) NOT NULL,

User_street VARCHAR(100) NOT NULL,

User_brgy VARCHAR(50) NOT NULL,

User_Municipality VARCHAR(50) NOT NULL,

User_province VARCHAR(50) NOT NULL,

FOREIGN KEY (User_id) REFERENCES tbl_user_profile(User_id) ON DELETE CASCADE

);

DROP TRIGGER IF EXISTS InsertUserData;

DROP TRIGGER IF EXISTS before_update_user_profile;

DROP PROCEDURE IF EXISTS InsertUserData;

DELIMITER $$
CREATE PROCEDURE InsertUserData(

IN firstName VARCHAR(50),

IN midName VARCHAR(50),

IN lastName VARCHAR(50),

IN suffix VARCHAR(10),

IN age INT,

IN gender VARCHAR(10),

IN birthDate DATE,

IN phoneNum VARCHAR(15),

IN email VARCHAR(100),

IN houseNum VARCHAR(10),

IN street VARCHAR(100),

IN brgy VARCHAR(50),

IN municipality VARCHAR(50),

IN province VARCHAR(50),

IN username VARCHAR(50),

IN password VARCHAR(255),

IN status VARCHAR(25),

IN Utype VARCHAR(25)

BEGIN

-- Declare and generate User_Fullname

DECLARE generatedFullname VARCHAR(100);

SET generatedFullname = CONCAT_WS(' ', firstName, IFNULL(midName, ''), lastName, IFNULL(suffix,


''));

-- Insert into tbl_user_profile

INSERT INTO tbl_user_profile (


User_Fullname, User_Firstname, User_Midname, User_Lastname, User_Suffix, User_age,
Acc_gender, Acc_Birthdate, User_type

) VALUES (

generatedFullname, firstName, midName, lastName, suffix, age, gender, birthDate, Utype

);

-- Insert into tbl_user_contact

INSERT INTO tbl_user_contact (

User_phonenum, Acc_Email

) VALUES (

phoneNum, email

);

-- Insert into tbl_user_address

INSERT INTO tbl_user_address (

User_Housenum, User_street, User_brgy, User_Municipality, User_province

) VALUES (

houseNum, street, brgy, municipality, province

);

-- Insert into tbl_accounts

INSERT INTO tbl_accounts (

Acc_Username, Acc_password, Acc_Status

) VALUES (

username, password, status

);

END$$

DELIMITER ;
SELECT

up.User_id AS 'User ID',

acc.Acc_password AS 'Password',

acc.Acc_Username AS 'Username',

up.User_Fullname AS 'Full Name',

up.User_Firstname AS 'First Name',

up.User_Midname AS 'Middle Name',

up.User_Lastname AS 'Last Name',

up.User_Suffix AS 'Suffix',

up.User_age AS 'Age',

up.Acc_gender AS 'Gender',

up.Acc_Birthdate AS 'Birthdate',

uc.User_phonenum AS 'Phone Number',

uc.Acc_Email AS 'Email',

ua.User_Housenum AS 'House Number',

ua.User_street AS 'Street',

ua.User_brgy AS 'Barangay',

ua.User_Municipality AS 'Municipality',

ua.User_province AS 'Province',

acc.Acc_Status AS 'Account Status',

up.User_type AS 'User Type'

FROM

tbl_user_profile up

LEFT JOIN

tbl_user_contact uc ON up.User_id = uc.User_id

LEFT JOIN

tbl_user_address ua ON up.User_id = ua.User_id


LEFT JOIN

tbl_accounts acc ON up.User_id = acc.Acc_id;

-- Example of calling the procedure for 25 records with alternating User_type values

CALL InsertUserData('John', 'A', 'Doe', '', 30, 'Male', '1994-05-15', '0912345678',


'johndoe@example.com', '101', 'Main St.', 'Brgy. 1', 'City A', 'Province A', 'johndoe123', 'password123',
'Active', 'User');

CALL InsertUserData('Jane', 'B', 'Smith', '', 28, 'Female', '1995-02-20', '0987654321',


'janesmith@example.com', '102', 'Second St.', 'Brgy. 2', 'City B', 'Province B', 'janesmith123',
'password456', 'Active', 'Admin');

CALL InsertUserData('Alice', 'C', 'Johnson', '', 25, 'Female', '1998-03-18', '0911222333',


'alicejohnson@example.com', '103', 'Third St.', 'Brgy. 3', 'City C', 'Province C', 'alicejohnson123',
'password789', 'Active', 'Driver');

CALL InsertUserData('Bob', 'D', 'Williams', '', 35, 'Male', '1989-07-22', '0944556677',


'bobwilliams@example.com', '104', 'Fourth St.', 'Brgy. 4', 'City D', 'Province D', 'bobwilliams123',
'password012', 'Inactive', 'User');

CALL InsertUserData('Charlie', 'E', 'Brown', '', 40, 'Male', '1984-08-25', '0977888999',


'charliebrown@example.com', '105', 'Fifth St.', 'Brgy. 5', 'City E', 'Province E', 'charliebrown123',
'password345', 'Active', 'Admin');

CALL InsertUserData('Diana', 'F', 'Wilson', '', 27, 'Female', '1996-09-30', '0922333444',


'dianawilson@example.com', '106', 'Sixth St.', 'Brgy. 6', 'City F', 'Province F', 'dianawilson123',
'password678', 'Inactive', 'Driver');

CALL InsertUserData('Eve', 'G', 'Moore', '', 22, 'Female', '2002-10-10', '0933444555',


'evemoore@example.com', '107', 'Seventh St.', 'Brgy. 7', 'City G', 'Province G', 'evemoore123',
'password901', 'Active', 'User');

CALL InsertUserData('Frank', 'H', 'Taylor', '', 33, 'Male', '1990-12-05', '0911555666',


'franktaylor@example.com', '108', 'Eighth St.', 'Brgy. 8', 'City H', 'Province H', 'franktaylor123',
'password234', 'Active', 'Admin');

CALL InsertUserData('Grace', 'I', 'Anderson', '', 26, 'Female', '1997-04-12', '0944666777',


'graceanderson@example.com', '109', 'Ninth St.', 'Brgy. 9', 'City I', 'Province I', 'graceanderson123',
'password567', 'Inactive', 'Driver');

CALL InsertUserData('Hank', 'J', 'Thomas', '', 31, 'Male', '1993-11-08', '0977888998',


'hankthomas@example.com', '110', 'Tenth St.', 'Brgy. 10', 'City J', 'Province J', 'hankthomas123',
'password890', 'Active', 'User');
CALL InsertUserData('Ivy', 'K', 'Jackson', '', 29, 'Female', '1994-06-18', '0988778899',
'ivyjackson@example.com', '111', 'Eleventh St.', 'Brgy. 11', 'City K', 'Province K', 'ivyjackson123',
'password123', 'Inactive', 'Admin');

CALL InsertUserData('Jack', 'L', 'White', '', 45, 'Male', '1978-09-02', '0922334455',


'jackwhite@example.com', '112', 'Twelfth St.', 'Brgy. 12', 'City L', 'Province L', 'jackwhite123',
'password456', 'Active', 'Driver');

CALL InsertUserData('Karen', 'M', 'Harris', '', 38, 'Female', '1985-05-30', '0933445566',


'karenharris@example.com', '113', 'Thirteenth St.', 'Brgy. 13', 'City M', 'Province M', 'karenharris123',
'password789', 'Inactive', 'User');

CALL InsertUserData('Larry', 'N', 'Clark', '', 27, 'Male', '1996-02-20', '0977889900',


'larryclark@example.com', '114', 'Fourteenth St.', 'Brgy. 14', 'City N', 'Province N', 'larryclark123',
'password012', 'Active', 'Admin');

CALL InsertUserData('Maggie', 'O', 'Lewis', '', 40, 'Female', '1983-11-14', '0922335566',


'magglewis@example.com', '115', 'Fifteenth St.', 'Brgy. 15', 'City O', 'Province O', 'magglewis123',
'password345', 'Inactive', 'Driver');

CALL InsertUserData('Nina', 'P', 'Young', '', 28, 'Female', '1995-04-25', '0933446677',


'nina.young@example.com', '116', 'Sixteenth St.', 'Brgy. 16', 'City P', 'Province P', 'nina.young123',
'password678', 'Active', 'User');

CALL InsertUserData('Oscar', 'Q', 'Scott', '', 32, 'Male', '1991-10-10', '0988779922',


'oscarscott@example.com', '117', 'Seventeenth St.', 'Brgy. 17', 'City Q', 'Province Q', 'oscarscott123',
'password901', 'Active', 'Admin');

CALL InsertUserData('Paul', 'R', 'King', '', 33, 'Male', '1990-12-25', '0911447788',


'paulking@example.com', '118', 'Eighteenth St.', 'Brgy. 18', 'City R', 'Province R', 'paulking123',
'password234', 'Inactive', 'Driver');

CALL InsertUserData('Quinn', 'S', 'Adams', '', 30, 'Female', '1994-01-02', '0933557788',


'quinnadams@example.com', '119', 'Nineteenth St.', 'Brgy. 19', 'City S', 'Province S', 'quinnadams123',
'password567', 'Active', 'User');

CALL InsertUserData('Rita', 'T', 'Nelson', '', 25, 'Female', '1998-07-16', '0944668899',


'ritanelson@example.com', '120', 'Twentieth St.', 'Brgy. 20', 'City T', 'Province T', 'ritanelson123',
'password890', 'Active', 'Admin');

CALL InsertUserData('Steve', 'U', 'Carter', '', 27, 'Male', '1996-03-22', '0977888877',


'stevecarter@example.com', '121', 'Twenty-First St.', 'Brgy. 21', 'City U', 'Province U', 'stevecarter123',
'password123', 'Inactive', 'Driver');

CALL InsertUserData('Tracy', 'V', 'Mitchell', '', 29, 'Female', '1994-06-12', '0922333444',


'tracymitchell@example.com', '122', 'Twenty-Second St.', 'Brgy. 22', 'City V', 'Province V',
'tracymitchell123', 'password456', 'Active', 'User');
CALL InsertUserData('Ursula', 'W', 'Perez', '', 32, 'Female', '1991-11-03', '0944666777',
'ursulaperez@example.com', '123', 'Twenty-Third St.', 'Brgy. 23', 'City W', 'Province W', 'ursulaperez123',
'password789', 'Inactive', 'Admin');

CALL InsertUserData('Victor', 'X', 'Roberts', '', 30, 'Male', '1993-08-18', '0933445599',


'victorroberts@example.com', '124', 'Twenty-Fourth St.', 'Brgy. 24', 'City X', 'Province X',
'victorroberts123', 'password012', 'Active', 'Driver');

CALL InsertUserData('Wendy', 'Y', 'Evans', '', 25, 'Female', '1998-10-25', '0922337788',


'wendyevans@example.com', '125', 'Twenty-Fifth St.', 'Brgy. 25', 'City Y', 'Province Y', 'wendyevans123',
'password345', 'Active', 'User');

CALL InsertUserData('Jane', 'A', 'Doe', '', 29, 'Female', '1995-04-10', '0912345678',


'janedoe@example.com', '112', 'Fourth Ave.', 'Brgy. 12', 'City J', 'Province J', 'janedoe123',
'securepass456', 'Active', 'User');

/*ROUTES*/

/*

(Rt_id, Rt_Name, Rt_Start, Rt_End)

*/

CREATE TABLE IF NOT EXISTS tbl_franchise (

Rt_id INT AUTO_INCREMENT PRIMARY KEY,

Rt_Name VARCHAR(100) unique NOT NULL,

Rt_Start VARCHAR(100) NOT NULL,

Rt_End VARCHAR(100) NOT NULL,

Rt_status int not null

);

INSERT INTO tbl_franchise (Rt_Name, Rt_Start, Rt_End, Rt_status)

VALUES

('Franchise 1', 'Start Point A1', 'End Point B1', 1),

('Franchise 2', 'Start Point A2', 'End Point B2', 1),

('Franchise 3', 'Start Point A3', 'End Point B3', 1),


('Franchise 4', 'Start Point A4', 'End Point B4', 1),

('Franchise 5', 'Start Point A5', 'End Point B5', 1),

('Franchise 6', 'Start Point A6', 'End Point B6', 1),

('Franchise 7', 'Start Point A7', 'End Point B7', 1),

('Franchise 8', 'Start Point A8', 'End Point B8', 1),

('Franchise 9', 'Start Point A9', 'End Point B9', 1),

('Franchise 10', 'Start Point A10', 'End Point B10', 1),

('Franchise 11', 'Start Point A11', 'End Point B11', 1),

('Franchise 12', 'Start Point A12', 'End Point B12', 1),

('Franchise 13', 'Start Point A13', 'End Point B13', 1),

('Franchise 14', 'Start Point A14', 'End Point B14', 1),

('Franchise 15', 'Start Point A15', 'End Point B15', 1),

('Franchise 16', 'Start Point A16', 'End Point B16', 1),

('Franchise 17', 'Start Point A17', 'End Point B17', 1),

('Franchise 18', 'Start Point A18', 'End Point B18', 1),

('Franchise 19', 'Start Point A19', 'End Point B19', 1),

('Franchise 20', 'Start Point A20', 'End Point B20', 1),

('Franchise 21', 'Start Point A21', 'End Point B21', 1),

('Franchise 22', 'Start Point A22', 'End Point B22', 1),

('Franchise 23', 'Start Point A23', 'End Point B23', 1),

('Franchise 24', 'Start Point A24', 'End Point B24', 1),

('Franchise 25', 'Start Point A25', 'End Point B25', 1),

('Franchise 26', 'Start Point A26', 'End Point B26', 1),

('Franchise 27', 'Start Point A27', 'End Point B27', 1),

('Franchise 28', 'Start Point A28', 'End Point B28', 1),

('Franchise 29', 'Start Point A29', 'End Point B29', 1),

('Franchise 30', 'Start Point A30', 'End Point B30', 1);

select*from tbl_franchise
/*

Driver info

(D_id, D_fullname, DL_num,DL_state,Dl_expr

*/

CREATE TABLE tbl_driver (

D_id INT PRIMARY KEY ,

D_fullname VARCHAR(255) NOT NULL,

DL_num VARCHAR(50) NOT NULL,

DL_dateissued VARCHAR(50) NOT NULL,

DL_expr DATE NOT NULL,

D_status VARCHAR(50) NOT NULL,

FOREIGN KEY (D_id) REFERENCES tbl_user_profile(User_id)

);

select*from tbl_driver;

/*

PUV info

(V_manufacturer, V_model, V_color, V_yrmodel, V_puvtype, V_vin, V_num, V_platenum, V_status,


V_driver

*/

CREATE TABLE tbl_PUV (

V_id INT PRIMARY KEY AUTO_INCREMENT, -- Unique identifier for each vehicle

V_manufacturer VARCHAR(100) NOT NULL,

V_model VARCHAR(100) NOT NULL,

V_color VARCHAR(50) NOT NULL,

V_yrmodel INT NOT NULL, -- Year model, typically an integer

V_puvtype VARCHAR(50) NOT NULL, -- PUV type (e.g., sedan, SUV)

V_vin VARCHAR(50) NOT NULL UNIQUE, -- Vehicle Identification Number

V_num VARCHAR(50) NOT NULL, -- Vehicle number


V_platenum VARCHAR(50) NOT NULL, -- Plate number

V_status VARCHAR(50) NOT NULL, -- Status (e.g., active, inactive)

V_driver VARCHAR(255), -- Driver's full name

FOREIGN KEY (V_driver) REFERENCES tbl_driver(D_fullname) -- Foreign key reference

);

CREATE TABLE tbl_franchise_reports (

Rtr_id INT AUTO_INCREMENT PRIMARY KEY,

Rtr_Name VARCHAR(100) not null,

Rtr_description VARCHAR(255) NOT NULL,

Rtr_datetime_ TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

FOREIGN KEY (Rtr_Name) REFERENCES tbl_franchise(Rt_Name) ON DELETE CASCADE

);

DELIMITER //

CREATE PROCEDURE InsertData_Rfranchise(

IN newData VARCHAR(255),

IN newDescription VARCHAR(255)

BEGIN

DECLARE maxRecords INT DEFAULT 60;

DECLARE currentDatetime DATETIME;

-- Get the current datetime

SET currentDatetime = NOW();

-- Check the count of records and delete the oldest if it exceeds the limit

IF (SELECT COUNT(*) FROM tbl_franchise_reports) >= maxRecords THEN

DELETE FROM tbl_franchise_reports


ORDER BY Rtr_id ASC

LIMIT 1;

END IF;

-- Insert the new record

INSERT INTO tbl_franchise_reports (Rtr_Name, Rtr_datetime_, Rtr_description)

VALUES (newData, currentDatetime, newDescription);

END //

DELIMITER ;

Insert tbl_franchise_reports(Rtr_Name, Rtr_description)

VALUES

('Franchise 1', 'Description for Franchise 1 report'),

('Franchise 2', 'Description for Franchise 2 report'),

('Franchise 3', 'Description for Franchise 3 report'),

('Franchise 4', 'Description for Franchise 4 report'),

('Franchise 5', 'Description for Franchise 5 report'),

('Franchise 6', 'Description for Franchise 6 report'),

('Franchise 7', 'Description for Franchise 7 report'),

('Franchise 8', 'Description for Franchise 8 report'),

('Franchise 9', 'Description for Franchise 9 report'),

('Franchise 10', 'Description for Franchise 10 report'),

('Franchise 11', 'Description for Franchise 11 report'),

('Franchise 12', 'Description for Franchise 12 report'),

('Franchise 13', 'Description for Franchise 13 report'),

('Franchise 14', 'Description for Franchise 14 report'),

('Franchise 15', 'Description for Franchise 15 report'),


('Franchise 16', 'Description for Franchise 16 report'),

('Franchise 17', 'Description for Franchise 17 report'),

('Franchise 18', 'Description for Franchise 18 report'),

('Franchise 19', 'Description for Franchise 19 report'),

('Franchise 20', 'Description for Franchise 20 report'),

('Franchise 21', 'Description for Franchise 21 report'),

('Franchise 22', 'Description for Franchise 22 report'),

('Franchise 23', 'Description for Franchise 23 report'),

('Franchise 24', 'Description for Franchise 24 report'),

('Franchise 25', 'Description for Franchise 25 report'),

('Franchise 26', 'Description for Franchise 26 report'),

('Franchise 27', 'Description for Franchise 27 report'),

('Franchise 28', 'Description for Franchise 28 report'),

('Franchise 29', 'Description for Franchise 29 report'),

('Franchise 30', 'Description for Franchise 30 report'),

('Franchise 31', 'Description for Franchise 31 report'),

('Franchise 32', 'Description for Franchise 32 report'),

('Franchise 33', 'Description for Franchise 33 report'),

('Franchise 34', 'Description for Franchise 34 report'),

('Franchise 35', 'Description for Franchise 35 report'),

('Franchise 36', 'Description for Franchise 36 report'),

('Franchise 37', 'Description for Franchise 37 report'),

('Franchise 38', 'Description for Franchise 38 report'),

('Franchise 39', 'Description for Franchise 39 report'),

('Franchise 40', 'Description for Franchise 40 report'),

('Franchise 41', 'Description for Franchise 41 report'),

('Franchise 42', 'Description for Franchise 42 report'),

('Franchise 43', 'Description for Franchise 43 report'),

('Franchise 44', 'Description for Franchise 44 report'),


('Franchise 45', 'Description for Franchise 45 report'),

('Franchise 46', 'Description for Franchise 46 report'),

('Franchise 47', 'Description for Franchise 47 report'),

('Franchise 48', 'Description for Franchise 48 report'),

('Franchise 49', 'Description for Franchise 49 report'),

('Franchise 50', 'Description for Franchise 50 report'),

('Franchise 51', 'Description for Franchise 51 report'),

('Franchise 52', 'Description for Franchise 52 report'),

('Franchise 53', 'Description for Franchise 53 report'),

('Franchise 54', 'Description for Franchise 54 report'),

('Franchise 55', 'Description for Franchise 55 report'),

('Franchise 56', 'Description for Franchise 56 report'),

('Franchise 57', 'Description for Franchise 57 report'),

('Franchise 58', 'Description for Franchise 58 report'),

('Franchise 59', 'Description for Franchise 59 report'),

('Franchise 60', 'Description for Franchise 60 report');

select*from tbl_franchise_reports;

SELECT

Rtr_Name AS 'Franchise Name',

Rtr_description AS 'Description',

Rtr_datetime_ AS 'Date/Time'

FROM tbl_franchise_reports

ORDER BY Rtr_datetime_ DESC;

CALL InsertData_Rfranchise('Franchise 29', 'add reports');


CREATE TABLE tbl_driver_reports (

Dr_id INT PRIMARY KEY,

Dr_Name VARCHAR(100) NOT NULL,

Dr_description VARCHAR(255) NOT NULL,

Dr_datetime_ TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

FOREIGN KEY (Dr_id) REFERENCES tbl_driver(D_id) ON DELETE CASCADE

);

DELIMITER //

CREATE PROCEDURE InsertData_Rdriver(

in newID VARCHAR(255),

IN newData VARCHAR(255),

IN newDescription VARCHAR(255)

BEGIN

DECLARE maxRecords INT DEFAULT 60;

DECLARE currentDatetime DATETIME;

-- Get the current datetime

SET currentDatetime = NOW();

-- Check the count of records in tbl_driver_reports and delete the oldest if it exceeds the limit

IF (SELECT COUNT(*) FROM tbl_driver_reports) >= maxRecords THEN

DELETE FROM tbl_driver_reports

ORDER BY Dr_id ASC

LIMIT 1;

END IF;
-- Insert the new record into tbl_driver_reports

INSERT INTO tbl_driver_reports (Dr_id, Dr_Name, Dr_datetime_, Dr_description)

VALUES (newID, newData, currentDatetime, newDescription);

END //

DELIMITER ;

select*from tbl_driver_reports;

CALL InsertData_Rdriver('Driver Name', 'Driver Description');

CREATE TABLE tbl_user_reports (

U_id INT PRIMARY KEY,

U_Name VARCHAR(100) NOT NULL,

U_description VARCHAR(255) NOT NULL,

U_datetime_ TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

FOREIGN KEY (U_id) REFERENCES tbl_user_profile(User_id) ON DELETE CASCADE

);

DELIMITER //

CREATE PROCEDURE InsertData_Uacc(

in newID VARCHAR(255),

IN newData VARCHAR(255),

IN newDescription VARCHAR(255)

BEGIN

DECLARE maxRecords INT DEFAULT 60;

DECLARE currentDatetime DATETIME;


-- Get the current datetime

SET currentDatetime = NOW();

-- Check the count of records in tbl_driver_reports and delete the oldest if it exceeds the limit

IF (SELECT COUNT(*) FROM tbl_user_reports) >= maxRecords THEN

DELETE FROM tbl_user_reports

ORDER BY U_id ASC

LIMIT 1;

END IF;

-- Insert the new record into tbl_driver_reports

INSERT INTO tbl_user_reports (U_id, U_Name, U_datetime_, U_description)

VALUES (newID, newData, currentDatetime, newDescription);

END //

DELIMITER ;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy