Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask DBMS Expert


Home >> DBMS

Part -1:

Question 1:

Rewrite this stored procedure to use Try-Catch block instead of the IF @@error method).

This example creates the AddSupplierProduct stored procedure that uses the @Oerror function to determine whether an error occurs when each INSERT statement is executed. If the error does occur, the transaction is rolled back.

https://queriesmssql.wordpress.comicategory/ad-hoc-queries/page/4/
USE Northwind
GO

CREATE PROCEDURE AddSupplierProduct
@CompanyName nvarchar (40) NULL,
@ContactName nvarchar (40) NULL,
@ProductName nvarchar (40) NULL,
@CategorylD int NULL,
@QuantityPerUnit nvarchar(20) NULL,
@Discontinued bit - NULL

AS
BEGIN TRANSACTION
INSERT Suppliers (CompanyName, ContactName)
VALUES (@CompanyName, @ContactName)
IF @@error <> 0
BEGIN
ROLLBACK TRAN
RETURN
END
DECLARE @InsertSupplierlD int
SELECT @InsertSupplierlDm@@identity
INSERT Products (ProductName, SupplierlD, CategorylD, QuantityPerUnit, Discontinued) VALUES (@ProductName, @InsertSupplierlD, @CategorylD, @QuantityPerUnit, @Discontinued)

IF @@error <> 0
BEGIN
ROLLBACK TRAN
RETURN
END
COMMIT TRANSACTION
/*
Note:

SupplierlD is auto-generated (Identity property is set to True) so it is not needed.

All the columns in the Suppliers table with the exception of CompanyName allow a null value.

All the columns in the Products table with the exception of ProductlD allow a null value including the two Foreign Keys of SupplierlD and CategorylD. If a SupplierlD or a CategorylD is given then it must exist in the corresponding table. The SupplierlD in this case is picked up from the @InsertSupplierlD. */

Question 2:

Create a stored procedure that allows me to enter the CustomerlD as a parameter and returns the CustomerlD and CompanyName.

Question 3:

The option is only needed if it is possible the query plan needed to be updated each time the stored procedure is executed.
• update
• re-execute
• recompile

• return

Part -2:

Create the following stored procedure (from Chapter 15 Exercise 1):
CREATE PROC spBalanceRange @VendorVar varchar(50) = 196', @BalanceMin money = 0, @BalanceMax money = 0
AS
SELECT VendorName
, InvoiceNumber
, InvoiceTotal - CreditTotal - PaymentTotal AS Balance
FROM Vendors JOIN Invoices ON Vendors.VendorlD = Invoices.VendorlD
WHERE VendorName LIKE @VendorVar
AND (InvoiceTotal - CreditTotal - PaymentTotal) BETWEEN @BalanceMin AND @BalanceMax ORDER BY Balance DESC;

Question 1:

EXEC spBalanceRange 'M%'

What does the exec above produce in terms of results. If you wanted companies that had 'Corp' in their name how would you code the EXEC statement?

Question 2:

EXEC spBalanceRange @BalanceMin = 200, @BalanceMax = 1000

What does the exec above produce in terms of results. What would happen it you miss coded the maximum balance to be 100 instead?

Question 3:

EXEC spBalanceRange [C,F]%, 0, 200

What does the exec above produce in terms of results. How would you code an EXEC statement to bring back those vendors whose name begin with the letter A thru L with a minimum balance of 100 and a maximum balance of 500?

DBMS, Programming

  • Category:- DBMS
  • Reference No.:- M91424179
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in DBMS

Relational database design a given the following business

Relational Database Design A) Given the following business rules, identify entity types, attributes (at least two attributes for each entity, including the primary key) and relationships, and then draw an Entity-Relation ...

Question lab 1 creating a database designthis assignment

Question: Lab 1: Creating a Database Design This assignment contains two (2) Sections: Database Design Diagram and Design Summary. You must submit both sections as separate files in order to complete this assignment. Not ...

Database design amp development assignment -assignment

Database Design & Development Assignment - Assignment title - Design and Implement a Relational Database for a local Print and Ink Refill Business. Learning Outcome - Use an appropriate design tool to design a relational ...

Instructionsfor decades relational databases remained

Instructions For decades, relational databases remained essentially unchanged; data was segmented into specific chunks for columns, slots, and repositories, also called structured data. However, in this Internet of Thing ...

Question 1 what isdata-manipulation language dml there are

Question: 1. What isData-Manipulation Language (DML)? There are four types of access in DML, explain each one. 2. Assume we have a Library Database consists of the following relations: author(author_id, first_name, last_ ...

Question talk about the importance of pulling data from

Question : Talk about the importance of pulling data from worksheets into a single sheet also the ways excel could be a solution to a complex challenge. The response must be typed, single spaced, must be in times new rom ...

Assignmenta restaurant is designing a database to keep

Assignment A restaurant is designing a database to keep track of customer services. A customer is defined as a customer ID, name, address and a telephone number. Customers are served by employees. Each employee is define ...

Real time analytics - data analytics assignment -this is a

Real Time Analytics - Data Analytics Assignment - This is a business analytics project aimed at generating innovative analytics solutions for a Global Food Consulting firm working in the area of Animal agriculture and fa ...

Objectivethe objective of this lab is to be familiar with a

OBJECTIVE: The objective of this lab is to be familiar with a process in big data modeling. You're required to produce three big data models using the MS PowerPoint software. This tool is available on UMUC Virtual Deskto ...

Question 1 a- consider that you are asked to design an

Question: 1. (a)- Consider that you are asked to design an entity relationship diagram based on the below scenario: A university consists of a number of departments (id, d_name) and each department offers some courses. A ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As