Click here to Skip to main content
15,896,348 members

Comments by Nikola Milovanovic (Top 3 by date)

Nikola Milovanovic 13-Dec-21 14:50pm View    
You helped me a lot! When I deleted Update_StavkaKataloga_GodinaKatalog trigger, all 3 solutions are working. Thank you very much
Nikola Milovanovic 13-Dec-21 13:13pm View    
Sorry for my late response:

create trigger [dbo].[Update_StavkaKataloga_GodinaKataloga]
on [dbo].[StavkaKataloga]
AFTER UPDATE
as
declare @GodinaKataloga int
select @GodinaKataloga=GodinaKataloga from inserted
if @GodinaKataloga not like (select GodinaKataloga from deleted)
begin
raiserror('Zabranjeno je direktno azuriranje GodineKataloga u StavciKataloga!', 16,1)
rollback
end

i dont want to allow the user to manualy update value in GodinaKataloga, and raise an error - Forbiden...
Nikola Milovanovic 13-Dec-21 11:28am View    
@Wendelius thanks for your reply! I tried your code and it worked, but before I saw yours I tried this one

create trigger Update_Katalog_Naziv
on Katalog
after update
as
if update (Godina)
begin
update StavkaKataloga
set GodinaKataloga=(select top 1 Godina from inserted)
from dbo.StavkaKataloga s
INNER JOIN INSERTED i ON s.IDKataloga = i.IDKataloga join Katalog k on s.IDKataloga = k.IDKataloga
where k.IDKataloga = s.IDKataloga
end

I am very thankful for your solution! The only thing that matters now is that all 3 options only work with lines disable trigger and enable trigger. I still cant find a way to make any of my solutions work without those lines. Are those lines mandatory with SQL server?