Deleting a row - Efficiency question

  • Thread starter Thread starter Dorian
  • Start date Start date
D

Dorian

I need to delete a row from a table if it is there (it may or may not be).
Is it better to first do a select to see if its there, then delete it if
present or just always do the delete which may not delete anything? I'd say
most of the time the row will not be there. Thanks.

-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
Dorian

1 - Check for it
2 - "IF" there", delete it
3 - "IF not there", don't

vs.

1 - Try to delete it
2 - Ignore/bypass the error if it isn't there

Looks to me like door #2...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Dorian said:
I need to delete a row from a table if it is there (it may or may not be).
Is it better to first do a select to see if its there, then delete it if
present or just always do the delete which may not delete anything? I'd say
most of the time the row will not be there. Thanks.


You can use the Execute method to run a delete query.
DELETE doesn't care if it deletes zero or a million records

CurrentDb.Execute "DELETE & FROM table " _
& "WHERE ...", dbFailOnError

You still nedd to use error handling to deal with all the
other thing that could go wrong (e.g. table doesn't exist,
etc).
 
Back
Top