Write a stored procedure that inserts a new row

Assignment Help Computer Engineering
Reference no: EM132214036

Write a stored procedure that inserts a new row into the Supplier table and then adds at least one new product that the new supplier stocks into the Products table.

This program must include the ability to handle a failed transaction in which case it should issue an error message and a rollback.

Note:

The ProductID in the Products table is auto-generated (Identity Specification is set to Yes). This means that Northwind only gets a certain product from a single Supplier.

In other words, Chai is only gotten from SupplierID = 1 which is Exotic Liquids.

Answer

A partial solution:

CREATE PROCEDURE AddSupplierProduct01

--The first set of columns information is for the Supplier table...

--This information is for the Product table...

AS

BEGIN TRANSACTION

INSERT Suppliers (CompanyName, ContactName, Address, City, Region,PostalCode, Country, Phone)

VALUES (@CompanyName, @ContactName, @Address, @City, @Region, @PostalCode, @Country, @Phone)

IF @@error <> 0

BEGIN

ROLLBACK TRAN

RETURN

END

DECLARE @InsertSupplierID int

SELECT @InsertSupplierID=@@identity

INSERT Products (ProductName, SupplierID, CategoryID, QuantityPerUnit, Discontinued)

VALUES (@ProductName, @InsertSupplierID, @CategoryID, @QuantityPerUnit, @Discontinued)

IF @@error <> 0

BEGIN

ROLLBACK TRAN

RETURN

END

COMMIT TRANSACTION

Another partial solution:

BEGIN TRY

BEGIN TRAN;

INSERT Suppliers

VALUES(@CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax, @HomePage)

DECLARE @SupplierID int

SELECT @SupplierID = SCOPE_IDENTITY()

INSERT Products

VALUES(@ProductName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)

COMMIT TRAN;

END TRY

BEGIN CATCH

ROLLBACK TRAN;

Print 'An error occured and the row was not added. Please try again.'

Reference no: EM132214036

Questions Cloud

Write a statistics class to compute mean and variance : Write a statistics class to compute mean, variance, max and min of a vector of numbers.
Take an input argument of r0 holding the address : Write a subroutine called TOLOWER. This takes an input argument of R0 holding the address of aproperly terminated string.
Evaluate the organisational structure of the workplace : Analyse the Internal, External and Industry Environment in which the work placement operates - Evaluate the organisational structure of the workplace
Write a static method with one integer parameter : Write a static method called Result with one integer parameter x that returns the value at polynomial 3x - 7.
Write a stored procedure that inserts a new row : Write a stored procedure that inserts a new row into the Supplier table and then adds at least one new product that the new supplier stocks.
Compute the checksum for a data table : Write a subroutine that computes the CHECKSUM for a data table (by XO Ring all the data bytes).
Find the cyclic rotation that is the smallest lexicographic : Write a SuffixArray client that, given a string, finds the cyclic rotation that is the smallest lexicographically in linear time.
Write and test a data structures template : Write the template for an array of capacity =2 (default constructor) of unspecified type.
Calculate the number of elements in an array not counting : MSP430G2553 :Subroutine expects the Input on the stack as shown above: The input is the starting address of an array consisting of word length elements.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Finding the maximum of a finite set of integers

Finding the maximum of a finite set of integers, making use of the fact that the maximum of n integers is the larger of the last integer in the list.

  Cost benefits to cloud computing

discuss whether or not there are cost benefits to cloud computing using specific examples. Be sure to include at least three reference sources.

  Write a piece of code that prompts the user for number

Write a piece of code that prompts the user for number of days, hours, minutes, and seconds (in that order).

  Determining the project schedule

Discuss in scholarly detail how you determine a project schedule once the critical path has been identified and how to adjust the schedule if the calculated project.

  What type of malware that is capable of infect a file

What type of malware that is capable of infect a file with an encrypted copy of itself, then modify itself when decoded to make almost impossible

  Discuss the potential customers for the product service

Describe the product/service including the benefits of using the product/service. Discuss the potential customers for this product/service

  Describe divide and conquer algorithms in your own words

Explain the "tradeoffs or decisions" required when writing/creating computer programs and how the "decisions" relate to Data Structures, algorithms.

  How would the redesign enhance successful teamwork

Brainstorm some ways to "redesign" your office space (or an office space you have previously worked in) on paper using virtual or flexible space.

  Create a class named car that has year property

Create a class named Car that has the following properties: The Year property holds the car's year model. The Make property holds the make of the car.

  Write simple text editor which stores a string of characters

Write a simple text editor, which stores and displays a string of characters using the list ADT, together with a cursor object that highlights a position.

  How do you refer to a range of cells

How do you refer to a range of cells? Express the following cells as ranges. All the cells in row 2 from C through N.

  What is the preset value or count

What is the accumulated value or count?

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