TAILIEUCHUNG - Executing SQL Server Stored Procedures phần 2

The output from this program is as follows: New ProductID = 81 Of course, depending on the existing rows in your Products table | The output from this program is as follows New ProductID 81 Of course depending on the existing rows in your Products table you ll get a different result. Executing the AddProduct2 Stored Procedure As you ll see the AddProduct2 procedure is similar to AddProduct except that it uses a RETURN statement instead of an OUTPUT parameter to return the ProductID for the new row. Listing shows the script that creates the AddProduct2 procedure. You ll need to run this script before running the C program. creates a procedure that adds a row to the Products table using values passed as parameters to the procedure. The procedure returns the ProductID of the new row using a RETURN statement CREATE PROCEDURE AddProduct2 @MyProductName nvarchar 40 @MySupplierID int @MyCategoryID int @MyQuantityPerUnit nvarchar 20 @MyUnitPrice money @MyUnitsInStock smallint @MyUnitsOnOrder smallint @MyReorderLevel smallint @MyDiscontinued bit AS - declare the @MyProductID variable DECLARE @MyProductID int - insert a row into the Products table INSERT INTO Products ProductName SupplierID CategoryID QuantityPerUnit UnitPrice UnitsInStock UnitsOnOrder ReorderLevel Discontinued VALUES @MyProductName @MySupplierID @MyCategoryID @MyQuantityPerUnit @MyUnitPrice @MyUnitsInStock @MyUnitsOnOrder @MyReorderLevel @MyDiscontinued - use the SCOPE_IDENTITY function to get the last - identity value inserted into a table performed within - the current database session and stored procedure - so SCOPE_IDENTITY returns the ProductID for the new row - in the Products table in this case SET @MyProductID SCOPE_IDENTITY RETURN@MyProductID Notice the RETURN statement at the end to return @MyProductID. Because AddProduct2 doesn t return a result set of rows you use the same four steps shown in the previous section to execute the procedure using . The only difference is in the construction of your EXECUTE .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.