เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ใช้ 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;
แก้ไขและรันโค้ด