使用存储过程进行 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;