Hi Gurus,
I'm trying to learn more about Stored Procedures. I don't have alot of time to practice with them but I created a Stored Procedure with two insert statements. It's supposed to perform inserts on two tables in a parent/child one-to-many relationship but I'm not sure if I have it right. I'm afraid some of the text I read was a little vague. If I can get the SP correct I plan to call it within ADO.NET with parameters mapped to textboxes, etc on a Window Form. The purpose of the form is Data Entry only. So I just want to make sure my SP is correct before I proceed.
Am I on the right track? What else should I consider? Really appreciate any guidance you can give me!
Thanks,
Tracy
ALTER PROCEDURE [usp_INSERT_NEW_CLASS]
(@InstID [int],
@ClassDate [smalldatetime],
@ClassCountyCode [char](2),
@ClsTltHrsTaught [smallint],
@ClsEnrolled [smallint],
@ClsGraduated [smallint],
@ClsSchoolHrs [bit],
@ClsMales [smallint],
@ClsWhite [smallint],
@ClsBlack [smallint],
@ClsNativeAm [smallint],
@ClsHispanic [smallint],
@ClsOther [smallint],
@ClsComment [varchar](100),
@AsstSSN [Char] (9),
@ClassID [int] OUTPUT)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [HUNTER_SAFETY_PROGRAM].[dbo].[CLASSES]
( [InstID],
[ClassDate],
[ClassCountyCode],
[ClsTltHrsTaught],
[ClsEnrolled],
[ClsGraduated],
[ClsSchoolHrs],
[ClsMales],
[ClsWhite],
[ClsBlack],
[ClsNativeAm],
[ClsHispanic],
[ClsOther],
[ClsComment])
VALUES
( @InstID,
@ClassDate,
@ClassCountyCode,
@ClsTltHrsTaught,
@ClsEnrolled,
@ClsGraduated,
@ClsSchoolHrs,
@ClsMales,
@ClsWhite,
@ClsBlack,
@ClsNativeAm,
@ClsHispanic,
@ClsOther,
@ClsComment)
SELECT @ClassID = SCOPE_IDENTITY()
INSERT INTO [HUNTER_SAFETY_PROGRAM].[dbo].[ASSISTANTS]
( [AsstSSN],
[ClassID])
VALUES
(@AsstSSN,
@ClassID)
END
I'm trying to learn more about Stored Procedures. I don't have alot of time to practice with them but I created a Stored Procedure with two insert statements. It's supposed to perform inserts on two tables in a parent/child one-to-many relationship but I'm not sure if I have it right. I'm afraid some of the text I read was a little vague. If I can get the SP correct I plan to call it within ADO.NET with parameters mapped to textboxes, etc on a Window Form. The purpose of the form is Data Entry only. So I just want to make sure my SP is correct before I proceed.
Am I on the right track? What else should I consider? Really appreciate any guidance you can give me!
Thanks,
Tracy
ALTER PROCEDURE [usp_INSERT_NEW_CLASS]
(@InstID [int],
@ClassDate [smalldatetime],
@ClassCountyCode [char](2),
@ClsTltHrsTaught [smallint],
@ClsEnrolled [smallint],
@ClsGraduated [smallint],
@ClsSchoolHrs [bit],
@ClsMales [smallint],
@ClsWhite [smallint],
@ClsBlack [smallint],
@ClsNativeAm [smallint],
@ClsHispanic [smallint],
@ClsOther [smallint],
@ClsComment [varchar](100),
@AsstSSN [Char] (9),
@ClassID [int] OUTPUT)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [HUNTER_SAFETY_PROGRAM].[dbo].[CLASSES]
( [InstID],
[ClassDate],
[ClassCountyCode],
[ClsTltHrsTaught],
[ClsEnrolled],
[ClsGraduated],
[ClsSchoolHrs],
[ClsMales],
[ClsWhite],
[ClsBlack],
[ClsNativeAm],
[ClsHispanic],
[ClsOther],
[ClsComment])
VALUES
( @InstID,
@ClassDate,
@ClassCountyCode,
@ClsTltHrsTaught,
@ClsEnrolled,
@ClsGraduated,
@ClsSchoolHrs,
@ClsMales,
@ClsWhite,
@ClsBlack,
@ClsNativeAm,
@ClsHispanic,
@ClsOther,
@ClsComment)
SELECT @ClassID = SCOPE_IDENTITY()
INSERT INTO [HUNTER_SAFETY_PROGRAM].[dbo].[ASSISTANTS]
( [AsstSSN],
[ClassID])
VALUES
(@AsstSSN,
@ClassID)
END