ใช้ SP เพื่อ INSERT
สร้าง stored procedure ชื่อ cusp_RideSummaryCreate ใน schema dbo เพื่อแทรกระเบียนลงในตาราง RideSummary
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การเขียนฟังก์ชันและ Stored Procedures ใน SQL Server
คำแนะนำการฝึกหัด
- กำหนด input parameter สองตัว ชื่อ
@DateParmและ@RideHrsParm - แทรก
@DateParmและ@RideHrsParmลงในคอลัมน์DateและRideHoursของตารางRideSummary - SELECT ระเบียนที่เพิ่งแทรกไป โดยกรองเฉพาะ 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;