MIS HW 3 OBrien Meaghan

docx

School

Pennsylvania State University *

*We aren’t endorsed by this school

Course

250

Subject

Computer Science

Date

Feb 20, 2024

Type

docx

Pages

2

Uploaded by meaghanobrien01

Report
Assignment #3 SQL Procedures, Functions, and Triggers Honor Code Bear in mind that you are bound by Smeal’s code of academic integrity. All work should be your own and completed individually. If you notice suspicious behavior by a classmate, please notify the instructor. Please sign (or type) your name in the statement below and copy to the top of the page that you are submitting: - I, Meaghan O'Brien , affirm that I have neither given, utilized, received, nor witnessed unauthorized aid on this deliverable and have completed this work honestly and according to the professor’s guidelines. - Procedures: 1. DELIMITER // CREATE PROCEDURE ProductPurchase( in prod_code varchar(15)) BEGIN DECLARE purchase_check INT DEFAULT 0; SELECT count(*) INTO purchase_check FROM cm_products WHERE Productcode = Prod_code; IF purchase_check>0 THEN SELECT DISTINCT productname, productline, priceeach, MSRP from cm products join cm_orderdetails on cm_products.productcode = cm_orderdetails.productcode; ELSE select 'the product has been sold or does not exists' err_msg from dual; END IF; END // DELIMITER ; Functions: 2. 1) create function calculate_sum (var1 int, var2 int) RETURNS DECIMAL(5,1) DETERMINISTIC return ((var1+var2)*var2) ; 2) select calculate_sum(9,7);
3. create function concat_hw_3 (x char, y char) returns char(100) return concat(x,' ',y, '!'); select concat_test('Spring','Break'); select concat('It is', ' Spring Break', '!') as FullString Triggers: 4. DELIMITER // CREATE TRIGGER update_table AFTER INSERT ON ProductLineCount FOR EACH ROW BEGIN UPDATE ProductLineCount SET TotalCount = (select count(*) from CM_products where productLine=NEW.productLine) where productLine=NEW.productLine; END // DELIMITER 5. DELIMITER // CREATE TRIGGER update_totalcount AFTER DELETE ON ProductLineCount FOR EACH ROW BEGIN UPDATE ProductLineCount SET TotalCount = (select count(*) from CM_products where productLine=OLD.productLine) where productLine=OLD.productLine; END // DELIMITER ; select * from productlinecount where productline = 'planes' or 'classic cars'
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help