tityo
14.09.06, 15:54
Napisałam trigera ale wyskakuje błąd: niejednoznaczna nazwa kolumny id_jachtu.
Co poprawić? HELP!
Relacje tabel: Jachty->Koszty->Wypozyczenia->Zwrot
create trigger stany on Zwrot for insert as
begin
declare @idw int, @ids int, @idz int, @idx int
set @idx = (select id_jachtu from Jachty join Koszty on Jachty.id_jachtu =
Koszty.id_jachtu where id_wypozyczenia= (select id_wypozyczenia from
inserted))
set @idw = (select id_wypozyczenia from inserted)
set @ids = (select stan_po from Zwrot where id_wypozyczenia = @idw)
set @idz = (select stan_przed from Jachty where id_jachtu = @idx )
if @ids > @idz
begin
print 'nastąpiło pogorszenie stanu jachtu'
update Jachty set stan_przed = @ids
where id_jachtu = @idx
end
else
begin
print 'stan jachtu sie nie zmienił'
rollback
end
end