lw_deleteLocation.sql
If Exists (Select * From sysobjects Where name = N'lw_deleteLocation' And user_name(uid) = N'dbo')
Drop Procedure dbo.lw_deleteLocation
Go
CREATE Procedure lw_deleteLocation(
@locationId int
)
As
set nocount on
--check for use of locationId. If it is used then don't delete it.
if exists(select * from [group] where locationId = @locationId)
begin
raiserror('locationID used in group. U cannot delete.',-1,-1) with nowait
return 1
end
if exists(select * from activity where locationId = @locationId)
begin
raiserror('locationID used in activity. U cannot delete.',-1,-1) with nowait
return 1
end
if exists(select * from location where locationId = @locationId)
begin
delete from location where locationId = @locationId
return 0
end
else
begin
raiserror('location with %ld : locationId doesnot exist',-1,-1,@locationId) with nowait
return 1
end
Go