BDG Scenario 3

lw_deleteGroup.sql

If Exists (Select * From sysobjects Where name = N'lw_deleteGroup' And user_name(uid) = N'dbo')
    Drop Procedure dbo.lw_deleteGroup
Go

 
CREATE Procedure lw_deleteGroup(
  @groupId int
 )
As
   set nocount on
   if exists(select * from personGroup where groupId = @groupId)
    begin
      raiserror('person is assigned to this group. U cannot delete',16,1) with nowait
      return 1
    end
   else if exists( select * from [group] where groupId = @groupId)
        begin
          delete from [group] where groupId = @groupId
          return 0
        end
        else
        begin
          raiserror('group with %ld groupId does not exist.',-1,-1,@groupId) with nowait
          return 1
        end
   

Go