Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trigger

Author  Topic 

Nil35
Starting Member

20 Posts

Posted - 2014-09-25 : 10:43:48


need to create trigger on table which will not allow to update value "1" into column and if tried to update.. then it should show error massage "Good To GO"

ID Name Roll
1 Ron 1
2 Jon 0
3 Nil 3
4 Par 1

if you try to update value "1" in Roll then it will through error

nil

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-09-25 : 12:04:26
[code]create trigger dbo.tr_MyTable on MyTable
for Update -- Insert, too?
as
begin
if exists (select * from inserted where Roll = 1)
raiserror("Good To GO", 16, 0) with LOG; -- "With LOG" is optional
end[/code]You probably want to modify or augment this logic but I think its a good start for your requirements.



Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy
Go to Top of Page

Nil35
Starting Member

20 Posts

Posted - 2014-09-25 : 14:12:33
Thank You so much John for reply,

I tried this and its working but i dont want Value "1" updated in table
above solution showing error massage but same time updating "1" in table
can you plz help me out with this..

nil
Go to Top of Page

Nil35
Starting Member

20 Posts

Posted - 2014-09-25 : 14:55:24
I found the solution
just using INSTEAD OF UPDATE in steade of FOR UPDATE

Thank You for Help
Nil

nil
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-09-25 : 18:27:30
My error handling should have included a rollback statement. When the code is free, sometimes you only get whacha pay for...



Too often we enjoy the comfort of opinion without the discomfort of thought. - John F. Kennedy
Go to Top of Page
   

- Advertisement -