開始使用免費開始

使用 SP 進行 INSERT

dbo 結構描述中建立一個名為 cusp_RideSummaryCreate 的預存程序,將一筆紀錄插入 RideSummary 資料表。

本練習屬於課程

在 SQL Server 中撰寫函式與預存程序

檢視課程

練習說明

  • 定義兩個輸入參數,名稱為 @DateParm@RideHrsParm
  • @DateParm@RideHrsParm 插入到 RideSummary 資料表的 DateRideHours 欄位中。
  • 選取剛插入的那筆紀錄,條件為 Date 等於 @DateParm

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- 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;
編輯並執行程式碼