1 Problem Domain

The problem domain is a simplified portion of what you came across earlier in the previous task.

Advertising agency Shine manages its client companies' advertising campaigns. It has a number of staff members with specialized skills. A record is kept of each client company, and of every campaign. Each campaign is based on a unique theme. A Shine staff may work on zero, or one or more campaigns at a time.

When a campaign starts, an estimate of the cost needs to be set and agreed upon. The actual cost of a campaign is calculated from staff time devoted to it. Staff members are paid (and clients charged) based on the hourly rate associated with their pay grade.

When the campaign is completed, an actual completion date and the actual cost are recorded and a single invoice for the whole campaign is sent to the client. The issue date and payment status of the invoice are also recorded. When the client pays, the date paid is recorded.

A relational data model for this domain is provided below to facilitate your understanding of the domain. A DDL script (create_DB.sql) for creating the corresponding database, and a DML script (populate_DB.sql) for populating this database with some sample data are being provided. Note that the DDL script will also create another table (not included in the diagram), called alerts, which is meant to contain messages as to which invoices are overdue.

Figure 1 : Relational Data Model see image.

2 Task Specifications

Task One

Create the tables listed in the relational data model as shown in Figure 1, as well as the alerts table, by running the provided DDL script provided in the folder. Then insert sample records to the tables by running the provided DML script provided. Verify that the tables are created and populated as intended.

Task Two and Three

Atemplate (stored_programs_template.sql) is provided for you to write the required programs (one trigger and two procedures). You must not change the "signature" (name, parameters with their types, orders, etc.) these programs. It is best to take this template and fill out the required codes. Remember to put your name and id number at the top as required. You should save this file with name of the following format, and submit it among other files: < yourLastname_yourFirstname>_programs.sql.

Task Two

Shine considers any invoice that remains unpaid for more than 30 days after it has been issued as overdue. Write a trigger called tr_overdue that fires whenever the invoice table is updated. If the STATUS of any invoice is updated to "OVERDUE" from something else, then a new row is inserted to the alerts table with the current date as the message_date, user as the origin, and 'Invoice with number: x is now overdue!' as the message, where x is the invoice number in question.

Task Three

As part of this task you will write two procedures:

1.Procedure sp_finish_campaign (in c_title varchar(30)) that takes as input the title of a campaign, and records that the corresponding campaign has been completed by (a) updating the CAMPAIGNFINISHDATE to the current date, and (b) updating the ACTUALCOST. The actual cost of a campaign is calculated from the number of hours different staff put into it on different dates, and the salary grade they were on such days. The procedure should signal an error with the message 'ERROR! Campaign title does not exist' if the input does not match any existing campaign.

2.Procedure sync_invoice() that identifies the invoices which are still recorded as UNPAID (as value of STATUS) more than 30 days after the invoice was issued. It updates those records, and sets the status to OVERDUE.

Task Four (Testing)

This task involves testing the code developed in Task Two and Task Three.

  • First you are required to test the programs you wrote against the sample data provided. The tests to be carried out, in the order given, is provided in the provided file: test_script.sql. These tests constitute a minimal test against a very small number of records. Look at this file carefully to understand what is being tested and what should be the expected result. Note the roles of setting autocommit off and the rollback statements.
  • Next you carry out a more extensive test by testing the programs against a larger set of records that are designed to easily expose any flaws in your programs. You do that by deleting records, adding records, or modifying the records in other ways, and then calling different procedures. You accordingly modify the file test_script.sql, and save it as < yourLastname_yourFirstname>_test_script.sql, and submit among other files.

3. Report Preparation

You will also prepare and submit a report (in the PDF format). A word file template for this purpose will be provided which you will complete, convert to pdf, and submit. The file you submit would be named: < yourLastname_yourFirstname>_report.pdf.

Your report should have the following sections:

1.Initial State of the database. Paste to the word file the screen shots showing the provided sample data in the tables.

2.Stored Programs. Paste into this section the programs you wrote (the sql file < yourLastname_yourFirstname>_programs.sql that you prepared).

3.Required Testing against Sample Database. Paste into this section the initial tests you ran (one by one) and then the corresponding results as screenshots. The provided script file lists what tests to run, how, and in which order.

4.More Extensive Testing. Explain what sort of changes you are going to make to which tables, what tests you are going to run, and why. Copy and paste from your file < yourLastname_yourFirstname>_test_script.sql the DML statements you used to modify the tables followed by the screenshots of the records in those tables; then copy and paste the procedure calls you made, and the screenshots of the records in the relevant tables (or the error messages).

5.Notes (optional). In this optional section, you might wish to note anything, such as whether you faced any particular difficulty in completing any of these tasks, the nature and extent of any help you received from anyone, and why.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.