Курсовая работа: Информационная система военного округа
/* Restrict child "Otdelenie" when parent "Vzvod" deleted */
if exists (select 1 from [Otdelenie] t, deleted d
where t.[Nazv_vzvoda] = d.[Nazv_vzvoda] and
t.[Nomer_podrazdelenia] = d.[Nomer_podrazdelenia] and
t.[nazvanie_armii] = d.[nazvanie_armii] and
t.[tip_i_nomer_obedinenia] = d.[tip_i_nomer_obedinenia] and
t.[Nazv_roti] = d.[Nazv_roti] and
t.[Mesto] = d.[Mesto])
begin
raiserror 50003 'Children still exist in table ''Otdelenie''. Cannot delete from parent table ''Vzvod''.'
rollback transaction
return
end
end
go
/* Delete trigger "td_Obedinenie" for table "Obedinenie" */
Create trigger [td_Obedinenie]
on [Obedinenie] for delete as
begin
declare @numrows int
select @numrows = @@rowcount
if @numrows = 0
return
/* Restrict child "Chast" when parent "Obedinenie" deleted */
if exists (select 1 from [Chast] t, deleted d
where t.[tip_i_nomer_obedinenia] = d.[tip_i_nomer_obedinenia] and
t.[Nomer_podrazdelenia] = d.[Nomer_podrazdelenia] and
t.[nazvanie_armii] = d.[nazvanie_armii])
begin