DBMS
DBMS
#Emily(Machines,Parts)
insert into Machines(MachineID,MachineName,PurchaseDate,MaintenanceDate)
values (1,'Lathe','2018-03-15',NULL), (2,'Drill','2019-05-20','2019-05-20'),
(3,'Milling','2020-07-01',NULL), (4,'CNC','2021-08-25','2024-02-10'),
(5,'Grinder','2022-01-10',NULL);
insert into Parts(PartID,PartName,MachineID,Quantity)
values (201,'Hydraulic Pump',1,15), (202,'Cooling Fan',2,5), (203,'Bearing',3,20), (204,'Drill
Bit',4,8), (205,'Tool Holder',5,12);
insert into MaintenanceLogs(LogID,MachineID,MaintenanceDate,Details)
values (301,1,'2024-01-15',"Routine maintenance performed."), (302,2,'2024-02-20',"Replaced
worn-out parts."), (303,3,'2024-03-01',"Calibrated machine."), (304,4,'2024-04-15',"Updated
software."),(305,5,'2024-05-20',"Checked all components.");
alter table Parts add PartPrice DECIMAL(10,2);
update Machines set MaintenanceDate=DATE_ADD(purchaseDate,INTERVAL 2 HOUR) where
(PurchaseDate < '2020-01-01' and MachineId not in (101,102) and MachineName != 'CNC');
delete from Parts where (Quantity < 10 and PartName != 'Hydraulic' or PartID in(201,202));
rename table MaintenanceLogs to MachineMaintenance;
#David(Categories, Medicines)
create table Categories( CategoryID int not null,
CategoryName varchar(100) not null,
constraint pk_categories primary key(CategoryID));
create table Medicines( MedicineID int not null,
MedicineName varchar(100) not null,
CategoryID int not null,
Stock int not null,
constraint pk_medicines primary key (MedicineID),
constraint fk_medicines_category foreign key(CategoryID) references Categories(CategoryID)
on delete cascade);
insert into Categories(CategoryID,CategoryName) values
(1,'Painkillers'),(2,'Antibiotics'),(3,'Vitamins'), (4,'Antiseptics'),(5,'Antifungals');
insert into Medicines (MedicineID,MedicineName,CategoryID,Stock) values
(101,'Paracetamol',1,50),(102,'Ibuprofen',1,30), (103,'Amoxicillin',2,40),(104,'Vitamin C',3,60),
(105,'Dettol',4,25);
delete from Categories where CategoryID=2;
#week8 - Triggers
#Before update trigger (customer_account)
DELIMITER //
CREATE TRIGGER update_customer_balance
BEFORE UPDATE ON customer_account
FOR EACH ROW
BEGIN
INSERT INTO mini_statement (acc_no, avail_balance)
VALUES (OLD.acc_no, OLD.avail_balance);
END;
//
DELIMITER;
update customer_account set avail_balance = avail_balance + 2000 where
acc_no = 9001;
update customer_account set avail_balance = avail_balance + 3000 where acc_no =
9004;
update customer_account set avail_balance = avail_balance - 5000 where acc_no =
9001;
update customer_account set avail_balance = avail_balance - 1000 where acc_no =
9001;
select * from mini_statement;
#Week10- XML
1. Free Formatter
2. Liquid Technologies - XSD Formatter
<bank>
<account>
<account_holder_name>xxxx</account_holder_name>
<account_number>123456789012</account_number>
<account_balance>10000</account_balance>
<contact>9441234578</contact>
</account>
</bank>