How can I create the following stored procedure in MySQL Workbench?:
Create a stored procedure named prc_new_rental to insert new rows in the RENTAL table. The procedure should satisfy the following conditions:
a. The membership number will be provided as a parameter.
b. Use a Count() function to verify that the membership number exists in the MEMBERSHIP table. If it does not exist, then a message should be displayed that the membership does not exist and no data should be written to the database.
c. If the membership does exist, then retrieve the membership balance and display a message that the balance amount is the previous balance. (For example, if the membership has a balance of $5.00, then display “Previous balance: $5.00”.)
d. Insert a new row in the rental table using the sequence created in Case 51 to generate the value for RENT_NUM, the current system date for the RENT_DATE value, and the membership number provided as the value for MEM_NUM.
You can create a stored procedure to insert new rows in a table, given it satisfies the provided conditions in the following way:
-- the stored procedure to be created is called prc_new_rental
-- a membership number is provided, which is passed as a parameter to the stored procedure
CREATE OR REPLACE PROCEDURE prc_new_rental (MEM_NUM_TEMP IN MEMBERSHIP.MEM_NUM%TYPE) AS COUNT_MEMBER NUMBER;
PREV_MEM_BALANCE MEMBERSHIP.MEM_BALANCE%TYPE;
BEGIN -- start of procedure
SELECT COUNT(*) INTO COUNT_MEMBER FROM MEMBERSHIP
-- count membership number into variable COUNT_MEMBER
WHERE MEM_NUM = MEM_NUM_TEMP;
IF COUNT_MEMBER = 0 THEN
dbms_output.put_line('A membership with number ' || MEM_NUM_TEMP || ' does not exist.');
ELSE
/* - if membership number count is not zero, then display previous balance and insert values in the table */
SELECT MEM_BALANCE INTO PREV_MEM_BALANCE FROM MEMBERSHIP
WHERE MEM_NUM = MEM_NUM_TEMP;
dbms_output.put_line('Previous Balance is: '|| To_Char(PREV_MEM_BALANCE, '$999,999,990.99'));
INSERT INTO RENTAL (RENT_NUM, RENT_DATE, MEM_NUM)
VALUES (RENT_NUM_SEQ.NEXTVAL, SYSDATE, MEM_NUM_TEMP);
END IF; -- end of if statement
END; -- end of procedure
How can I create the following stored procedure in MySQL Workbench?: Create a stored procedure na...
Using the MySQL Workbench create a new database using your design specifications Add at least 10 records to your tables. Note: Certain tables may not require 10 records and that is ok as long as your main tables have 10 or more Create MySQL statements that will retrieve all records or rows from the tables in your database Create 10 MySQL statements that will retrieve specified records or rows from one table in your database Create 10 MySQL statements that...
Use MySQL Workbench for these questions. Do NOT use Lucidchart. MySQL Workbench has more capability than Lucidchart, as it allows creation of DDL SQL from the model. Turn in 1 Workbench file , 1 document with the forward-engineered sql statements, and a Word document with your inserted data. This problem mimics the one from the previous assignment. Model it in Workbench, then forward-engineer the database script and import into your database. If the import fails, fix it in the model,...
Using the Class database, answer the following questions: 1. Create a stored procedure that for any student id entered, a list of absences for that student will be displayed. Display the student id, student name, and the dates the student has missed. Display the total number of days missed for this student. Name this stored procedure StudentAbsences . a. What did you write for your stored procedure? Insert the snip of the contents of the stored procedure here: b. Run...
Create a stored procedure that allows a user to select a bat’s manufacturer and (optionally) serial number using a stored procedure. The output should display all of the players who use the bat’s manufacturer. If the serial number is also provided, only display the players who use that bat’s manufacturer and serial number. Make sure you use a CREATE PROCEDURE call and insert this procedure into the existing database. Submit a document that includes: 1. Commented code for the stored...
Use MySQL Workbench to create a simple ER model and use the Forward Engineering functionality of Workbench to create a simple DB (specs follow). This focuses on how MySQL Workbench is used to create a model and then a DB from it, rather than on ER modeling. The sample model you are to create is on books, authors, and publishers - a model that could be part of a larger ER model for a library. A book has an ISBN...
Create a series of ER Diagrams using MySQL Workbench. Each question below is a different version of the same database, with each version increasing in complexity. You need to submit an ER diagram for each version, in pdf or png format. The easiest would be to export your diagrams as png format and insert them into an MS Word document. For each ER diagram clearly indicate primary keys, foreign keys, and relationships, including cardinality (i.e. 1-to-many). Indicate in your diagram...
Q.5] Answer the following questions based on the company database (based on the homework assignment 2) y database (based on the homework assignment 2) 3 IPage 1. For each department whose average employee salary is more than $30,000, write a SQL statement to retrieve the department name and the number of employees working for that department 2. Write a SQL statement to retrieve first name, last name, and address of each employee who lives in Houston, TX. 3. Write a...
Write a procedure called insert_emp which inserts a new employee into f_emps. Pass the employee id, last name, salary, and department id to the procedure as IN parameters. The procedure should call your check_dept function to verify that the passed department id exists in the f_depts table. If it exists, insert the employee. If it does not exist, use DBMS_OUTPUT.PUT_LINE to display a suitable error message. Save your code.
Need help modifing the below ap_equipment_insert_3 stored procedure to use the bebug argument properly and to add an output clause on the insert near the bottom. alter Procedure ap_Equipment_Insert_3 -- Store values in equipment table. -- Return identifier of the record to the caller. ( @chvMake varchar(50), @chvModel varchar(50), @chvEqType varchar(30) ) As declare @intEqTypeId int, @ErrorCode int, @intEqId int -- does such eqType already exist in the database If Not Exists (Select...
Create a procedure to update the sales history table following the requirements below. A table creation script is provided below. a) Call the procedure: UPDATE_SALES_HISTORY (The procedure name is important for our scripts to test and grade your code; please do not rename it (otherwise our scripts will not run and your score will be 0). b) The procedure takes 2 parameters: (4-digit-year, 2-digit-month). Both parameters will be numeric, e.g., (2019, 11) will denote 2019 (year) and November (month). The...