Question

In: Computer Science

Step 2: Create Stored Procedures to Add/Update/Delete an entity table Create a script to create a...

Step 2: Create Stored Procedures to Add/Update/Delete an entity table

Create a script to create a table named ProjectBilling which will have the following columns:

• projectBillID char(6) : A 6 character unique identifier (numbers and letters)

• TransAmount decimal(16,9) : The amount of the transaction

• TransDesc varchar(255): A description of the transaction

• TransDate datetime: The date of the transaction

• projectID char(4):The Id of the project

• accountMgr char(8):The employee who manages the bill ledger Include this create table script in your script.

You will create the SQL Scripts to create procedures to insert/ update data. The following definitions specify the parameters that can be passed in.

The underlined parameters are required, but the other parameters will be optional.

Make sure that your procedure inserts records if the required parameters do not exist, but they update records if the required parameters do exist.

For example: If SP_AddUpdateProjBill: passes in projectBillID “AA0102” and it DOESN’T exists in the projectbilling table(s) , it will insert the values passed in.

If SP_AddUpdateProjectBill: passes in projectBillID “AA0102” and it DOES exists in the projectbilling table(s) , it will UPDATE the values passed in for the AA0102 record.

Procedures Needed: - SP_AddUpdateProjectBill: Adds/Updates the ProjectBilling Table with all the field information.

o Parameters: projectBillID, TransAmount, TransDesc, TransDate, projectId, accountMgr. -

SP_DeleteProjectBill: Deletes a project bill by the ProjectBill Id.

o Parameters: projectBillId

Solutions

Expert Solution

Below is the code to create a table:

CREATE TABLE ProjectBilling

( projectBillID char(6) primary key,

TransAmount decimal(16,9),

TransDesc varchar(255),

TransDate datetime,

projectID char(4),

accountMgr char(8) )

Now let's see the procedure to insert/update table:

CREATE PROCEDURE SP_AddUpdateProjectBill (@projectBillID char(6), @TransAmount decimal(16,9), @TransDesc varchar(255), @TransDate datetime, @projectID char(4), @accountMgr char(8) )

AS
BEGIN


IF EXISTS (Select * from ProjectBilling where projectBillID=@projectBillID

                               and TransAmount = @TransAmount

                               and TransDesc = @TransDesc

                               and TransDate = @TransDate

                               and projectID = @projectID

                               and accountMgr = @accountMgr )

BEGIN

      UPDATE ProjectBilling

      SET

          TransAmount = @TransAmount

          TransDesc = @TransDesc

          TransDate = @TransDate

          projectID = @projectID

          accountMgr = @accountMgr

       WHERE where projectBillID=@projectBillID

END
END

ELSE

BEGIN

      INSERT INTO ProjectBilling

      VALUES (@projectBillID, @TransAmount, @TransDesc, @TransDate, @projectID, @accountMgr )

END

END

Now let us see the stored procedure to delete from the table:

CREATE PROCEDURE SP_DeleteProjectBill ( @projectBillId char(6) ) 
AS  
BEGIN  
DELETE FROM  ProjectBilling WHERE  projectBillId= @projectBillId
END

Related Solutions

SQL stored procedures Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your...
SQL stored procedures Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your base table structures. The stored procedure should accept the parameters needed to input the data for each table. NOTE: You do not need to input the UserID or RoleID. These are surrogate keys and the system automatically inserts them when you insert a row in the tables.   On execution, the stored procedure should check the database to see if the user exists, if so,...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Create a stored procedure that can be used to add a student to the school and...
Create a stored procedure that can be used to add a student to the school and a section of a course. 1. If the student already exists, then just add him to the section (do not update information like address). 2. The procedure will require the following arguments (see table definition for types): A. Salutation B. First Name C. Last Name D. Street Address (including City) E. ZIP Code F. Phone Number G. Employer Name (if any) H. Course Number...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import...
---In the code, create add and delete a student by ID number when prompted /////////////////////////////////////////////////////////////// import java.util.Scanner; public class COurseCom666 {     private String courseName;     private String [] students = new String[1];     private int numberOfStudents;     public COurseCom66(String courseName) {         this.courseName = courseName;     }     public String[] getStudents() {         return students;     }     public int getNumberOfStudents() {         return numberOfStudents;     }     public String getCourseName() {         return courseName;     }     public...
Describe how foreign keys impact the ability to add or delete rows from a table or...
Describe how foreign keys impact the ability to add or delete rows from a table or the ability to drop tables from a database schema.
create a todo app using React and MongoDB. User can also delete the tasks, add tasks,...
create a todo app using React and MongoDB. User can also delete the tasks, add tasks, update tasks and edit tasks using edit, del, update and add button.
Please provide a step by step solution create a Vacation Budget worksheet Add at least 6...
Please provide a step by step solution create a Vacation Budget worksheet Add at least 6 other expenses related to your planned vacation (car rental etc.) enter an estimate of the cost of for each item Use a function to calculate the total estimated costs. g) Enter a function to calculate the average cost per day. h) Create a chart (you choose the type) in this same worksheet based on this trip to display the estimated costs. Add a title...
Write a SQL script to add another table to your database. Include these fields in your...
Write a SQL script to add another table to your database. Include these fields in your Product table: Field Name Description Data Type Sample Value ProductID Product ID integer 5 ProductName Product Name varchar(50) candle Description Product Description varchar(255) Bee’s wax candle picUrl Filename of the product’s picture varchar(50) candle.gif Price Product Price decimal 10.99           ProductID should be the Primary Key. It is an auto-increment field.           The Price field stores prices to 7 significant digits and to 2...
Consider these two Oracle Stored Procedures / Functions: Assume that both have been successfully compiled. CREATE...
Consider these two Oracle Stored Procedures / Functions: Assume that both have been successfully compiled. CREATE OR REPLACE FUNCTION CALC(pamt number) RETURN number AS vTot number; BEGIN     vTot := pamt + pamt ;      Return vTot; END; CREATE OR REPLACE PROCEDURE SHOW(pstr VARCHAR2) AS BEGIN     dbms_output.put_line(pstr); END; Write an anonymous block that executes the function named CALC and then the procedure called SHOW. The output generated by SHOW must be: The total is 20
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT