使用 SP 進行 INSERT
在 dbo 結構描述中建立一個名為 cusp_RideSummaryCreate 的預存程序,將一筆紀錄插入 RideSummary 資料表。
本練習屬於課程
在 SQL Server 中撰寫函式與預存程序
練習說明
- 定義兩個輸入參數,名稱為
@DateParm與@RideHrsParm。 - 將
@DateParm與@RideHrsParm插入到RideSummary資料表的Date與RideHours欄位中。 - 選取剛插入的那筆紀錄,條件為 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;