Writing Functions and Stored Procedures in SQL Server
Meghan Kwartler
IT Consultant
Decouples SQL code from other application layers
Improved security
Decouples SQL code from other application layers
Improved security
Performance
CREATE PROCEDURE dbo.cusp_TripSummaryCreate (
@TripDate as date,
@TripHours as numeric(18, 0)
) AS BEGIN INSERT INTO dbo.TripSummary(Date, TripHours)
VALUES
(@TripDate, @TripHours)
SELECT Date, TripHours
FROM dbo.TripSummary
WHERE Date = @TripDate END
CREATE PROCEDURE cusp_TripSummaryRead
(@TripDate as date)
AS
BEGIN
SELECT Date, TripHours
FROM TripSummary
WHERE Date = @TripDate
END;
CREATE PROCEDURE dbo.cusp_TripSummaryUpdate
(@TripDate as date,
@TripHours as numeric(18,0))
AS
BEGIN
UPDATE dbo.TripSummary
SET Date = @TripDate,
TripHours = @TripHours
WHERE Date = @TripDate
END;
CREATE PROCEDURE cusp_TripSummaryDelete
(@TripDate as date,
@RowCountOut int OUTPUT)
AS
BEGIN
DELETE
FROM TripSummary
WHERE Date = @TripDate
SET @RowCountOut = @@ROWCOUNT
END;
Writing Functions and Stored Procedures in SQL Server