Bắt đầu ngayBắt đầu miễn phí

Dùng SP để INSERT

Tạo một stored procedure tên cusp_RideSummaryCreate trong schema dbo để chèn một bản ghi vào bảng RideSummary.

Bài tập này là một phần của khóa học

Viết Hàm và Thủ Tục Lưu Trữ trong SQL Server

Xem khóa học

Hướng dẫn bài tập

  • Định nghĩa hai tham số đầu vào tên @DateParm@RideHrsParm.
  • Chèn @DateParm@RideHrsParm vào các cột DateRideHours của bảng RideSummary.
  • Select bản ghi vừa được chèn, nơi Date bằng @DateParm.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

-- Create the stored procedure
CREATE PROCEDURE dbo.cusp_RideSummaryCreate 
    (___ date, ___ numeric)
AS
BEGIN
SET NOCOUNT ON
-- Insert into the Date and RideHours columns
INSERT ___ dbo.___(___, ___)
-- Use values of @DateParm and @RideHrsParm
___(___, ___) 

-- Select the record that was just inserted
___
    -- Select Date column
	___,
    -- Select RideHours column
    ___
FROM dbo.RideSummary
-- Check whether Date equals @DateParm
WHERE Date = @DateParm
END;
Chỉnh sửa và Chạy Mã