Jump to content

Sql Server Trigger Sorusu


adam4
 Share

Recommended Posts

Arkadaşlar şimdi benim bi tablom var. Tablo adı : yonetim

tablado ad,konum,bolum ve maas kolonları var. Konumu "yönetici" olanların bolumlerini update etmemi engelleyecek ve bir hata mesajı verecek bir trigger yazmak istiyorum.

Ama sadece bolumlerini engellecek. Maas kolonunda oynama yapabilmem gerekiyor. Bu konuda bana yardımcı olursanız çok sevinirim.

 

şimdiden teşekkür ederim.

Link to comment
Share on other sites

2 saat önce, syntax_error yazdı:

alter trigger trg_yonetim on yonetim for update as
if (update(bolum))
begin
 if (SELECT konum FROM INSERTED) ='yonetici'
 RAISERROR (N'yöneticinin konumunu değişiremezsiniz',16,1)
end

çok sağolun hocam teşekkür ederim.

Birde gözünüzden kaçmış sanırım geri alması için rollback eklememiz gerekiyor.

 

Link to comment
Share on other sites

Alıntı

alter proc teslim (@ilce nvarchar(20))
as
if @ilce != ilce
begin
print 'böyle kayıtlı ilce yok'
end

else
begin
SELECT ilce,nerede from kargo Where ilce = @ilce and nerede = 'TESLİM EDİLDİ'

end

 

Birde arkadaşlar böyle bir prosedür yazıyorum. benim if - else'te koşul koyarken mesela yazdıgım ilce orda yoksa bana mesaj vermesini istiyorum.

koşul olarak eşit değil ifadesi bana mantıklı geliyo ama demekki sql'in dilinde mantıksız. Bu koşulu nasıl sağlamam gerekiyor.

 

Bu arada tablo adı kargo.

Kolonlar id , ilce , nerede 

Link to comment
Share on other sites

alter proc teslim (@ilce nvarchar(20))
as
if ISNULL( ilce,0)
begin
print 'böyle kayıtlı ilce yok'
end

else
begin
SELECT ilce,nerede from kargo Where ilce = @ilce and nerede = 'TESLİM EDİLDİ'

end

Aslında ISNULL ile yapılabilir bu işler için onu kullanır ama into ya atıp ordan da sorgulayabilirsin iş yerinde oracle kullandığım için syntax hatalı olabilir.

 ALTER PROC TESLIM(@ILCE NVARCHAR(20))
 SELECT COUNT(ilce) INTO ILCEVARMI FROM KARGO
 IF ILCEVARMI < 0
 BEGIN
 PRINT 'BOYLE BIR KAYITLI ILCE YOK'
 END
 ELSE
 BEGIN
 SELECT ilce,nerede from kargo Where ilce = @ilce and nerede = 'TESLİM EDİLDİ'
 END
        

Edited by SimpsoN_Bart
  • Like 2
Link to comment
Share on other sites

Alıntı

Msg 4145, Level 15, State 1, Procedure but, Line 4
An expression of non-boolean type specified in a context where a condition is expected, near 'begin'.
Msg 156, Level 15, State 1, Procedure but, Line 7
Incorrect syntax near the keyword 'else'.

Hocam bu hatayı aldım ISNULL ile. İf'e başka bir koşul koyunca @ilce=5 gibi çalışıyor kodlar.

Sorun ne olabilir sizce?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...