Create execute and test a stored procedure

Assignment Help Database Management System
Reference no: EM13911695

The purpose of this assignment:To assess your ability to:

• Apply active database concepts such as stored procedures and triggers in a relational database.

This assignment assumes previous access to Oracle using the Oracle SQL Developer application and assignment 6-1 & 7-1 have been completed. I also attached BaseTable.sqlfor you to start on this exercise in case you had issue in previous assignments.

Assignment Details:

• Assume that you have created the following tables in your database at previous labs:

1856_Execute and test a stored procedure.png

DEPARTMENT(DEPT_ID, DEPT_NAME)
TEAM(TEAM_ID, TEAM_NAME, DEPT_ID)
APPLICATION(APP_ID, APP_NAME, TEAM_ID, DB_ID,SERVER_ID)
SERVER(SERVER_ID,SERVER_NAME,HOST)
DATABASE(DB_ID,DB_NAME,SERVER_ID)
OUTAGE(OUTAGE_ID, APP_ID, OUTAGE_START_TIME, OUTAGE_END_TIME, OUTAGE_CAUSS, DESCRIPTION)
• Assume that the DEPARTMENT and TEAM tables include the following information.
DEPARTMENT table TEAM tabe

1. Run "BaseTable.sql" to drop and recreate the tables, and insert data into the base tables if you do not have the tables and data ready as stated above.

Here is the output file if everything runs correctly:

2. Create, execute and test a stored procedure:
a. Create a stored procedure called Get_team_namethat takes DEPT_ID as a parameter and return the team name from TEAM table. Copy the stored procedure into Word document.
i. Remember to end the stored procedure with a slash on a line by itself (after the END; in the procedure itself).
ii. Test steps:Copy each step SQL script and output into Word document.
1. Run SELECT * from TEAM WHERE DEPT_ID=101;
2. Execute your stored procedure: exec Get_team_name(101);

b. (Option) Create a stored procedure called remove_deptthat takes DEPT_ID as a parameter and delete a department with that dept_id from DEPARTMENT table. Copy the stored procedure into Word document.
i. Remember to end the stored procedure with a slash on a line by itself (after the END; in the procedure itself).
ii. Teststeps: Do the following steps to test your stored procedure. Copy each step SQL script and output into Word document.
1. Run the following two SQL commands:
a. SELECT * from DEPARTMENT WHERE DEPT_ID=101;
b. SELECT * from TEAM WHERE DEPT_ID=101;
2. Execute your procedure to delete DEPT_ID = 101;
3. Run select in step i again.
a. SELECT * from DEPARTMENT WHERE DEPT=101;
b. SELECT * from TEAM WHERE DEPT=101;
4. Answer this question: Did the corresponding records with dept_id = 101 in table TEAM get deleted automatically? Can you explain why?
5. Issue a ROLLBACK command to undo all changes.
6. Rerun select in step i :
a. SELECT * from DEPARTMENT WHERE DEPT_ID=101;
b. SELECT * from TEAM WHERE DEPT_ID=101;
7. Answer the question: Do the records related todept_id = 101 exist in DEPARTMENT and TEAM tables? Explain why?

3. Creating and Testing SQL Triggers. Save the SQL code of the trigger in a separate .sql script file called trig_dept_onUpdate.sql . Then, include each SQL command and its corresponding output in your Word document.
a. Create a trigger named trig_dept_onUpdatethat will automatically setdept_idto the new one in TEAM table when a corresponding department is modified. For example, if dept_id = 103is changed to 204 in DEPARTMENT table, then the dept_id of 103 inteam table will be set to 204 in TEAM table.
b. Test Steps:Copy each step SQL script and output into Word document.
i. Run the following two SQL commands:
1. SELECT * from DEPARTMENT WHERE DEPT_ID=103;
2. SELECT * from TEAM WHERE DEPT_ID=103;
ii. Run trig_dept_onUpdate trigger to update the dept_id to 204 where dept_id = 103.
iii. Run the same following SQL commands:
1. SELECT * from DEPARTMENT WHERE DEPT_ID=103;
2. SELECT * from TEAM WHERE DEPT_ID=103;
3. SELECT * from DEPARTMENT WHERE DEPT_ID=204;
4. SELECT * from TEAM WHERE DEPT_ID=204;
i. Remember, your trigger should only make changes to the particular records where DEPT_ID=103 that is affected by the UPDATE statement. (i.e., you may also want to check the values to the other records in the TEAM table to guarantee they have not changed with this update, etc.)
ii. Remember to end each trigger with a slash on a line by itself (after the END; in the trigger itself).
4. Your assignment should include:
a. stored procedureGet_team_name or remove_deptscript with output
b. triggertrig_dept_onUpdatescript with output
c. Testing steps with output result

Note: Please copy both SQL statement and output result in every step into Word document with step number (for example: Step#1, Step #2, etc). Points will be deducted if any of them is not missed. For each step, the output should follow each SQL statement.

Note: Common Lab Expectations - These apply to all SQL Labs for this class.

1) Always include set echo on;SQL command at the beginning of every SQL script (.sql) file you create or before inputting any SQL commands directly into the worksheet area in SQL Developer (along with the set serveroutput on;command right after it).
Example scripts and the corresponding output
Ch07_Artist_ORA_Script_Example.sql

Ch07_Artist_ORA_Script_Example_Output.lst

2) Include commit; command for INSERT/UPDATE/DELETE to ensure the changes is stored permanently in the database.
a. When writing your SQL query commands and gathering the output from them (to be put into a Word document), you must be sure to include the step #, the SQL command(s), and it corresponding output(s), in that order in the Word document. Refer to Example1.doc. (https://download.franklin.edu/COMP/281/Example1.doc
b. Use the drop table <tablename> cascade constraints; command BEFORE creating any table in your SQL (.sql) file or in the worksheet area so that this file can be rerun when necessary. You will get table does not exist the first time. Ignore it.
c. Insert will append the data into existing table. If you want to remove the data in the table and then insert the new data, use delete from <tablename>; command BEFORE doing any inserts into tables in your .sql file or in the worksheet area.
d. Use the comment feature in SQL Developer in your .sql script files and in your worksheet view to include any comments. These are input into your file by surrounding your comments with a /* ... */. An example is: /* this is a comment */ Also see it used in the .sql file hyperlink in #1 above. These comments should be used to designate which commands and output apply to which steps.

More resources and helpful hints:

Resources on Triggers and procedures:

https://www-db.stanford.edu/~ullman/fcdb/oracle/or-triggers.html
https://tucano.tucanowebdesign.com/oracle/tutorial5.html
https://www.pgrocer.net/Cis50/procedures.html
https://www.sqlteam.com/article/an-introduction-to-triggers-part-i
https://dba.fyicenter.com/faq/sql_server_2/ALTER_TRIGGER_Modifying_Existing_Triggers.html
https://download.oracle.com/docs/cd/B19306_01/server.102/b14220/triggers.htm

Viewing Defined Triggers

To view a list of all defined triggers, use: select trigger_name from user_triggers;

For more details on a particular trigger:
select trigger_type, triggering_event, table_name, referencing_names, trigger_body
from user_triggers
where trigger_name = '<trigger_name>';

Viewing Defined Procedures

To view a list of all defined procedures, use:
select object_name, procedure_name from user_procedures;

For more details on a particular procedure:
select * from user_procedures where procedure_name = '<procedure_name>';

Displaying Trigger Definition Errors

If you get a message: "Warning: Trigger created with compilation errors." you can see the error messages by typing:

show errors trigger <trigger_name>;

Alternatively, you can type, SHO ERR (short for SHOW ERRORS) to see the most recent compilation error. Note that the reported line numbers where the errors occur may not be accurate.

To see a list of the fields available to you, do a descuser_triggers; and/or a descuser_procedures;

Reference no: EM13911695

Questions Cloud

How many concrete trucks would it take to deliver concrete : How many concrete trucks would it take to deliver the concrete required to construct a 5' wide, 4" thick sidewalk around Lake Erie
Estimated age of the fossil : The specimen was found to have a ratio of 14C/12C 0.795 times that found in current living plants. What would be the estimated age of the fossil remains? The half-life for carbon -14 is 5720 years.
What annual rate of return would she have earned : Suppose that, on March 28, 2020, this security's price is $38,260. If an investor had purchased it for $24,099 at the offering and sold it on this day, what annual rate of return would she have earned?
Compute the gain or loss to mann on the settlement of debt : Compute the gain or loss to Mann on the settlement of the debt
Create execute and test a stored procedure : Apply active database concepts such as stored procedures and triggers in a relational database - Create, execute and test a stored procedure.
Find the probability that the store will meet its goal : Find the probability that the store will meet its goal during a particular week. Find the probability that the store will not meet its goal during a particular week.
Prepare the journal entries to record the sale, purchase : Prepare the journal entries to record the sale, purchase, and adjusting entries related to the trading securities in the last quarter of 2010.
How much goodwill will result from this transaction : Raider Co. recently acquired all of Lost Arc, Inc.'s net assets in a business acquisition.
Find the probability that no accidents will occur : Find the probability that no more than 12 accidents will occur during a particular year. Find the probability that no accidents will occur during a particular year.

Reviews

Write a Review

Database Management System Questions & Answers

  Suppose a movie database in which data is recorded about

suppose a movie database in which data is recorded about the movie industry. the data needs are summarized as follows

  Explain relational database design

How would you change the current design and how does your new design address the problems you have identified with the current design.

  A uml class diagram to describe the ordering system class

a UML class diagram to describe the ordering system class

  The database used for the relational algebra simple one

Relational Algebra- The database used for this question is a very simple one with the following schema: (Primary keys are bold, foreign keys are underlined)

  Draw context diagram that represent supply ordering system

Draw a context diagram that represents a Supply Ordering System (SOS).

  Review the data analysis and consider the coding activities

Review the data analysis and consider the coding activities you have engaged. Consider the kinds of data that would be generated through the data collection techniques anticipated for your qualitative research plan.

  Implement a series of queries on the database

As a way to demonstrate success, you are to implement a series of queries on the database to reflect the business logic of Best Home real estate.

  Determine the names of all tracks from table

All primary keys are underlined. All foreign keys have same name as primary key that they are referencing. Determine the names of all Tracks which are more than 10 minutes (600,000 ms) long.

  Analyze the data in at least three different ways

Analyze the data in at least three different ways. Each form of Data Analysis should be provided on a separate, appropriately labeled worksheet. It is expected that each sheet will be professionally formatted and clearly documented with titles, co..

  What is sql and for what purpose is it used in databases

What is SQL and for what purpose is it used in databases

  Create a crow''s foot erd using a specialization hierarchy

Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate. Tiny Hospital keeps information on patients and hospital rooms

  Create a provider database and related reports

Create a provider database and related reports and queries to capture contact information for potential PC componentproviders that might be used to purchase the equipment your specified in your MS Word project - the PC specifications

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