create proc PROC_Del_Advertisers
@id varchar(8) --广告主ID
as
declare @AccountType nvarchar(10) --账号类型
select @AccountType = AccountType from Same where Id=@id
declare @error int --记录错误
declare @AdSeriesId varchar(8),@AdGroupId varchar(8),@AdvertisingId varchar(8) --广告系列ID,广告组ID,广告ID
declare @AdKeyWordId int,@SiteSettingsId int,@WebMasterId int --广告关键字ID,网站设置ID,网站主ID
declare @WebMasterManagerId varchar(8) --网站信息ID
begin transaction --事务开始
if @AccountType='广告主' --处理删除广告主
begin
select @AdSeriesId = Id from AdSeries where Same=@id --查询对应的广告系列ID
select @AdGroupId = Id from AdGroup where AdSeries=@AdSeriesId --查询对应的广告组ID
select @AdvertisingId = Id from Advertising where AdGroup=@AdGroupId--查询对应的广告ID
select @AdKeyWordId = Id from AdKeyWord where AdGroup=@AdGroupId --查询对应的关键字ID
delete from AdKeyWord where Id = @AdKeyWordId --删除关键字
delete from Advertising where Id = @AdvertisingId --删除广告
delete from AdGroup where Id = @AdGroupId --删除广告组
delete from AdSeries where Id = @AdSeriesId --删除广告系列
delete from Same where Id = @id --删除广告主
end
if @AccountType='网站主' --处理删除网站主
begin
select @WebMasterId=Id from WebMaster where Same = @id --查询对应的网站主Id
select @WebMasterManagerId = Id from WebSiteManager where WebMaster=@WebMasterId --查询对应的网站信息ID
select @SiteSettingsId=Id from SiteSettings where WebSiteManager=@WebMasterManagerId --查询对应的网站设置ID
delete from SiteSettings where id=@SiteSettingsId --删除网站设置
delete from WebSiteManager where Id=@WebMasterManagerId --删除网站信息
delete from WebMaster where Id=@WebMasterId --删除网站主
delete from Same where Id = @id --删除广告主
end
set @error = @error+@@error
if @error > 0
rollback transaction --回滚事务
else
commit transaction --提交事务
go这事务位置放错了吗?
为什么错误回滚不了?
@id varchar(8) --广告主ID
as
begin
declare @AccountType nvarchar(10) --账号类型
select @AccountType = AccountType from Same where Id=@id
declare @error int --记录错误
declare @AdSeriesId varchar(8),@AdGroupId varchar(8),@AdvertisingId varchar(8) --广告系列ID,广告组ID,广告ID
declare @AdKeyWordId int,@SiteSettingsId int,@WebMasterId int --广告关键字ID,网站设置ID,网站主ID
declare @WebMasterManagerId varchar(8) --网站信息ID
begin transaction --事务开始
if @AccountType='广告主' --处理删除广告主
begin
select @AdSeriesId = Id from AdSeries where Same=@id --查询对应的广告系列ID
select @AdGroupId = Id from AdGroup where AdSeries=@AdSeriesId --查询对应的广告组ID
select @AdvertisingId = Id from Advertising where AdGroup=@AdGroupId--查询对应的广告ID
select @AdKeyWordId = Id from AdKeyWord where AdGroup=@AdGroupId --查询对应的关键字ID
delete from AdKeyWord where Id = @AdKeyWordId --删除关键字
delete from Advertising where Id = @AdvertisingId --删除广告
delete from AdGroup where Id = @AdGroupId --删除广告组
delete from AdSeries where Id = @AdSeriesId --删除广告系列
delete from Same where Id = @id --删除广告主
end
if @AccountType='网站主' --处理删除网站主
begin
select @WebMasterId=Id from WebMaster where Same = @id --查询对应的网站主Id
select @WebMasterManagerId = Id from WebSiteManager where WebMaster=@WebMasterId --查询对应的网站信息ID
select @SiteSettingsId=Id from SiteSettings where WebSiteManager=@WebMasterManagerId --查询对应的网站设置ID
delete from SiteSettings where id=@SiteSettingsId --删除网站设置
delete from WebSiteManager where Id=@WebMasterManagerId --删除网站信息
delete from WebMaster where Id=@WebMasterId --删除网站主
delete from Same where Id = @id --删除广告主
end
set @error = @error+@@error
if @error > 0
rollback transaction --回滚事务
else
commit transaction --提交事务
end
go
create proc PROC_Del_Advertisers
@id varchar(8) --广告主ID
as
declare @AccountType nvarchar(10) --账号类型
select @AccountType = AccountType from Same where Id=@id
declare @error int --记录错误
set @error=0 --记得初始化
declare @AdSeriesId varchar(8),@AdGroupId varchar(8),@AdvertisingId varchar(8) --广告系列ID,广告组ID,广告ID
declare @AdKeyWordId int,@SiteSettingsId int,@WebMasterId int --广告关键字ID,网站设置ID,网站主ID
declare @WebMasterManagerId varchar(8) --网站信息ID
begin transaction --事务开始
if @AccountType='广告主' --处理删除广告主
begin
select @AdSeriesId = Id from AdSeries where Same=@id --查询对应的广告系列ID
select @AdGroupId = Id from AdGroup where AdSeries=@AdSeriesId --查询对应的广告组ID
select @AdvertisingId = Id from Advertising where AdGroup=@AdGroupId--查询对应的广告ID
select @AdKeyWordId = Id from AdKeyWord where AdGroup=@AdGroupId --查询对应的关键字ID
delete from AdKeyWord where Id = @AdKeyWordId --删除关键字
set @error = @error+@@error
delete from Advertising where Id = @AdvertisingId --删除广告
set @error = @error+@@error
delete from AdGroup where Id = @AdGroupId --删除广告组
set @error = @error+@@error
delete from AdSeries where Id = @AdSeriesId --删除广告系列
set @error = @error+@@error
delete from Same where Id = @id --删除广告主
set @error = @error+@@error
end
if @AccountType='网站主' --处理删除网站主
begin
select @WebMasterId=Id from WebMaster where Same = @id --查询对应的网站主Id
select @WebMasterManagerId = Id from WebSiteManager where WebMaster=@WebMasterId --查询对应的网站信息ID
select @SiteSettingsId=Id from SiteSettings where WebSiteManager=@WebMasterManagerId --查询对应的网站设置ID
delete from SiteSettings where id=@SiteSettingsId --删除网站设置
set @error = @error+@@error
delete from WebSiteManager where Id=@WebMasterManagerId --删除网站信息
set @error = @error+@@error
delete from WebMaster where Id=@WebMasterId --删除网站主
set @error = @error+@@error
delete from Same where Id = @id --删除广告主
end
if @error > 0
rollback transaction --回滚事务
else
commit transaction --提交事务
go
set @error = @error+@@error
@id varchar(8) --广告主ID
as
declare @AccountType nvarchar(10) --账号类型
select @AccountType = AccountType from Same where Id=@id
declare @error int --记录错误
Select @error =0
declare @AdSeriesId varchar(8),@AdGroupId varchar(8),@AdvertisingId varchar(8) --广告系列ID,广告组ID,广告ID
declare @AdKeyWordId int,@SiteSettingsId int,@WebMasterId int --广告关键字ID,网站设置ID,网站主ID
declare @WebMasterManagerId varchar(8) --网站信息ID
begin transaction --事务开始
if @AccountType='广告主' --处理删除广告主
begin
select @AdSeriesId = Id from AdSeries where Same=@id --查询对应的广告系列ID
select @AdGroupId = Id from AdGroup where AdSeries=@AdSeriesId --查询对应的广告组ID
select @AdvertisingId = Id from Advertising where AdGroup=@AdGroupId--查询对应的广告ID
select @AdKeyWordId = Id from AdKeyWord where AdGroup=@AdGroupId --查询对应的关键字ID
delete from AdKeyWord where Id = @AdKeyWordId --删除关键字
delete from Advertising where Id = @AdvertisingId --删除广告
delete from AdGroup where Id = @AdGroupId --删除广告组
delete from AdSeries where Id = @AdSeriesId --删除广告系列
delete from Same where Id = @id --删除广告主
end
if @AccountType='网站主' --处理删除网站主
begin
select @WebMasterId=Id from WebMaster where Same = @id --查询对应的网站主Id
select @WebMasterManagerId = Id from WebSiteManager where WebMaster=@WebMasterId --查询对应的网站信息ID
select @SiteSettingsId=Id from SiteSettings where WebSiteManager=@WebMasterManagerId --查询对应的网站设置ID
delete from SiteSettings where id=@SiteSettingsId --删除网站设置
delete from WebSiteManager where Id=@WebMasterManagerId --删除网站信息
delete from WebMaster where Id=@WebMasterId --删除网站主
delete from Same where Id = @id --删除广告主
end
set @error = @error+@@error
if @error > 0
rollback transaction --回滚事务
else
commit transaction --提交事务
go