Friday, March 9, 2012

Needs Help With Modifying Stored Procedure

I need help with modifying this procedure to join JobTypeGallery, Remodel on JobTypeGallery.TypeID and Remodel.TypeID.

I would like for it the procedure to not allow deleting a record from JobTypeGallery if there are any records in Remodel Table that is associated with JobTypeGallery. Can someone please help me modify this stored procedure?


Create PROCEDURE [dbo].[spDeleteJobTypeGallery] @.typeid int AS delete from jobTypeGallery where typeID = @.typeid
GO

(1) You should be setting up an FK reference to the Remodel table from JobTypeGallery table.

(2) Modify your proc to check for existence of any records in the Remodel table before you delete here. You might also want to RaiseError appropriately. Also you can modify the proc to delete from the Remodel table first if any records exist there before deleting from jobTypeGallery.

Create PROCEDURE [dbo].[spDeleteJobTypeGallery] @.typeidint AS BEGINIFNOT EXISTS (SELECT *FROM RemodelWHERE TypeId = @.TypeID)delete from jobTypeGallerywhere typeID = @.typeidENDGO

|||

Hope this will help you!!!

delete from JobTypeGallery, Remodel where JobTypeGallery.typeid!=Remodel.typeid

/

delete from JobTypeGallery, Remodel where JobTypeGallery.typeid<>Remodel.typeid

|||

The below stored procedure:

Create PROCEDURE [dbo].[spDeleteJobTypeGallery]
@.typeidint
AS
BEGIN

IFNOT EXISTS (SELECT *FROM RemodelWHERE TypeId = @.TypeID)
delete from jobTypeGallerywhere typeID = @.typeid
END
GO

worked well. I need help with creating a message that would display if there are no pictures associated with a jobtypegallery in the Remodel table. Can someone please help me with this?

|||

Read up books online for OUTPUT parameters. You can return an appropriate value via OUTPUT parameter to front end and display an appropriate message to the user.

No comments:

Post a Comment