Create a trigger

Assignment Help Other Subject
Reference no: EM132211484

Assignment

Firstly, you have to setup the user lib_jcxxxxxx account and create the required tables. To do so, you must use the 3 given files in ass2_sql_files.zip. You should perform the following steps:

1. Run SQL Developer
2. Connect Oracle DB by the user system
3. Open the script create_user.sql and change jc000000 to your jc username, for example, jc123456
4. Run the script create_user.sql
5. You can now disconnect the system connection
6. Connect Oracle DB by the user lib_jcxxxxxx
7. Open the script lib_tables.sql and run it
Note: lib_tables.sql creates tables with basic constraints, no additional constraints
8. Open the script insert_records.sql and run it

If there is anything wrong, you can always re-run the 3 files again.

You have tologin as a lib_jcxxxxxx user to write SQL and PL/SQL to define triggers, stored procedures/functions as specified in the following subsections. You should also include SQL/PLSQL statements to test the triggers and procedures/functions that you must implement. Make sure that you test single row as well as multiple row actions. Include comments for each testing statement to indicate the trigger or the procedure/function in which it applies and the expected results of the trigger firing or procedure/function executing.

Task 1: TR_date_returned_chktrigger

You should create a trigger called TR_date_returned_chk(Loan table) to comparedate_returnedto the current system date before inserting or updating a row in Loan table.If date_returned isgreater than the current system date then raise an application error.

You should produce your answer in Microsoft Word with a heading Task2containing:
- the required trigger (PL/SQLstatements)
- testing: write 2 SQL statements to insert data into the table for testing trigger. One is for a valid record and another one is for an invalid record.
- showing the testing results

Hint:
create or replacetrigger TR_date_returned
before insert or update of date_returned on Loan
for each row
begin
if (:new.date_returned> sysdate) then
RAISE_APPLICATION_ERROR(-20000, date_returned cannot be greater than current date');
end if;
end;

-- test valid date_returned
...
-- results
...
-- test invalid date_returned
...
-- results
...

Task 2: CreateFUNC_is_available_copyfunction

Create a function called FUNC_is_available_copy to check if a copy is available or not. This function should contain the following input parameter: copy_id. It should return 1 if available and 0 if not available.

You should produce your answer in Microsoft Word with a heading Task2containing:
- the required function (PL/SQLstatements)
- testing:write an anonymous block (PL/SQLstatements) to call the function to test.
- showing the testing results. Both cases: available and not available.

Hint: A copy is unavailable if and only if the copy is found in the Loan table with date_returned being null.

Hint:

create or replaceFUNCTION FUNC_GET_AVAILABLE_COPY(...)
RETURN NUMBER AS
-- define a variable to return a number and initialise it to 1 (available)
-- define another variable to get a Loan's column; it's will be used in "select ... into ..." statement
BEGIN
-- write a "select ... into" statement to get a record from the Loan table having the given copy_id and
-- date_returned being null
-- if found then set the variable to 0 (unavailable)
RETURN the variable;
EXCEPTION
WHEN no_data_found THEN
RETURN the variable; -- it is 1 as defined
END FUNC_GET_AVAILABLE_COPY;

-- testing function: you can write an anonymous block of code to test the function
declare
-- a variable to pass to the function
begin
-- call the function and output the result
end;

-- testing results
...

Task 3: Create TR_add_loantrigger

You should create a trigger called TR_add_loan. This trigger fires before inserting a row in the Loan table. If the copy_id is not available then raise an application error. Hint: Use the function FUNC_is_available_copy.

You should produce your answer in Microsoft Word with a heading Task3containing:
- the required trigger (PL/SQLstatements)
- testing: write 2 SQL statements to insert data into the table for testing trigger. One is for a valid record and another one is for an invalid record.
- showing the testing results

Task 4: CreateFUNC_get_book function

Create a function called FUNC_get_book to retrieve book_id, title, shelf_letter, call_number and no_of_copies with a given isbn. This function should contain the following input parameter: isbn_p; the following output parameters:title_p, shelf_letter_p, call_number_p andno_of_copies_p. It should return the book_id if found and -1 if not found.

You should produce your answer in Microsoft Word with a heading Task4containing:
- the required function (PL/SQLstatements)
- testing:write an anonymous block (PL/SQLstatements) to call the function to test.
- showing the testing results. Both cases: Found and not found. For having a record, should output title_p, shelf_letter_p, call_number_p andno_of_copies_p.

Task 5: CreateTR_insert_or_update_booktrigger

Create a trigger called TR_insert_or_update_book. This trigger fires after inserting or updating a row in the Booktable. For inserting, it will add its corresponding copy records into Copies table. If a book has 5 copies then 5 copy records will be added into the Copies table. The copy_numberin the Copies table must be between 1 and no_of_copies.For updating, if the new value of no_of_copies is less than the old value then raise an application error. If the new value of no_of_copies is greater than the old one then write a log record into the Log table and add additional copy records into the Copies table as well. Hint: copy_id should be obtained by the SELECT sequence_name.NEXTVAL/CURRVAL INTO sequence_value FROM dual;

You should produce your answer in Microsoft Word with a heading Task5containing:
- the required trigger (PL/SQLstatements)
- inserting data into the Booktable for testing trigger
- updating data on the Booktable for testing trigger
- showing the testing results

Attachment:- Assignment-Part.rar

Verified Expert

This is sql assignment.Loan, book,copies are given databases. Using these databases, triggers and functions are written.These triggers and functions are tested and screenshots are given in report file.

Reference no: EM132211484

Questions Cloud

Write a program that reverses a text file : Write a program that reverses a text file by using a stack. The user interface must consist of 2 list boxes and 3 buttons. The 3 buttons are.
Write a program that will take a sentence : Write a program that will take a sentence (a single String) such as "the lazy dog tripped over the bar stool", picks out the individual words (substrings).
Write a program that simulates the functionality : Write a program that simulates the functionality of a vending machine having the following characteristics: The vending machine offers 5 products.
Create an array to hold average house price : Create an array to hold average house price for the each of past 25 years for a single family residence of 1500 square feet. Initialize the array.
Create a trigger : CP5503 - Enterprise Database Systems - Oracle - write an anonymous block (PL/SQLstatements) to call the function to test
Write the program to show how depth-first search works : Write the program to show how depth-first search works on the following graph. Assume that the DFS procedure considers the vertices in alphabetical order.
WAP that takes integer as number of both rows and columns : Write a program ShiftNumbers.java that takes integer M as the number of both rows and columns for your 2D array. Create the same exact following 2D array.
Write a program to simulate managing les on disk : Write a program to simulate managing les on disk. De ne the disk as a onedimensional array disk of size numOfSectors*sizeOfSector, where sizeOfSector indicates.
Write a program to read the salary for ten employees : Write a program to read the Salary for 10 employees. Calculate average of Salary. Calculate the Max Salary and Min Salary.

Reviews

Write a Review

Other Subject Questions & Answers

  How to make training in house or buy training from vendor

You are a training manager for the organization and should consider whether to make training in house or buy training from a vendor.

  What is one possible explanation for her forgetting

Janice studied a lot for a test, but then when she was taking the test, she forgot most of what she had studied.

  Evaluate the effectiveness of the authors claim

Identify the author's claim. Evaluate the effectiveness of the author's claim. Identify and analyze the supporting evidence connected to the claim.

  Review the article on unmotivated police officers

Review the article on unmotivated police officers at the link provided. What can/should a Supervisor do to remedy the situation

  What are the differences between ai and being human

What are the differences between AI and being human? Should AI have rights like humans do? Where do you draw the line?

  Strategic leaders play in the implementation process

What are the dual roles that strategic leaders play in the implementation process? What decisions do they need to make in terms of strategy and resources?

  Articles on causes of infant mortality in us

Gather and examine data about infant mortality rates in U.S. Then study research in the medical causes of infant mortality. Using the Online Library, choose and read five articles in peer-reviewed journals such as the Journal of Epidemiology, Journ..

  Discuss how you would conduct a follow up study to this one

the purpose of the final exam is to assess your understanding of the main statistical concepts covered in this course

  What kind of crimes are women incarcerated for?

What kind of crimes are women incarcerated for?

  Degree program in criminal justice

In 200 words. How would a $1,000 scholarship positively impact a person ability to pursue their degree program in criminal justice and how would a person intend to utilize the degree after graduation.

  Important qualities that a manager must possess

What do you feel are the most important qualities that a manager must possess to be effective? What do you feel are the most important qualities for a leader to possess to be effective

  Discuss advertising during the super bowl is pricey

Advertising during the Super Bowl is pricey and reserved for mega brands, but local television stations are allowed to air local advertisements during the broad

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd