Unix Technical Forum

UPDATE instead of DELETE

This is a discussion on UPDATE instead of DELETE within the MySQL forums, part of the Database Server Software category; --> Hi all, is it possible to avoid deleting of a row when a DELETE query is executed? I want ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:37 AM
mario.cartia@gmail.com
 
Posts: n/a
Default UPDATE instead of DELETE

Hi all,
is it possible to avoid deleting of a row when a DELETE query is
executed? I want to UPDATE row (setting for example a boolean field)
insted of deleting it.

I can do this in Oracle and Postgres (with INSTEAD OF rule). Is it
possible to do this in MySQL?

Thank you in advance.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:37 AM
Bill Karwin
 
Posts: n/a
Default Re: UPDATE instead of DELETE

mario.cartia@gmail.com wrote:
> Hi all,
> is it possible to avoid deleting of a row when a DELETE query is
> executed? I want to UPDATE row (setting for example a boolean field)
> insted of deleting it.
>
> I can do this in Oracle and Postgres (with INSTEAD OF rule). Is it
> possible to do this in MySQL?


I don't think so. MySQL triggers can do other operations in addition to
the named operation (for example, inserting to a log table when an
operation is performed on a given table), and BEFORE INSERT/UPDATE
triggers can modify values entered into a row, but there's no way to
tell it to skip the operation.

A typical usage of INSTEAD OF, in addition to the usage you're
describing, is to allow non-updateable views to be made updateable, by
providing custom logic in the trigger to update the base tables of the
view. However, MySQL docs explicitly say that one cannot associate a
trigger with a view or a temporary table.

It sounds like you're doing someting akin to overloading the DELETE
statement, to make it do something other than its assigned semantics.
SQL is not an object-oriented language, and does not support overloading
in this way. I think you need to use UPDATE when you mean UPDATE, as in
this case.

Regards,
Bill K.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:33 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com