Link to home
Start Free TrialLog in
Avatar of softbless
softbless

asked on

Trigger to prevent update in Mysql

Dear All,

Please help me providing trigger in mysql that prevent update of some particular record in a table.

For example :
Name             Hobby
-------------      -----------
Willy                Swimming
Willy                Singing
Susan             Reading
Marie               Reading
Susan             Swimming
Michael            Soccer

As you can see Susan has 2 hobbies. I want to prevent update if there is a query that update all record with Susan as name.

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

in MYSQL, triggers are "for each row":
http://dev.mysql.com/doc/refman/5.1/en/create-trigger.html

so, you cannot see inside the trigger if there are several rows being updated.

what you should do is to create a unique index or unique constraint on username + hobbyname, so an update cannot udpate all the rows from 1 username to the same hobby ...
ASKER CERTIFIED SOLUTION
Avatar of Sandeepratan
Sandeepratan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of softbless
softbless

ASKER

ok thanks Sandeepratan
I'll try
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.