Performance/good practice question - should I check if object exists or ju开发者_Python百科st delete it?
So:
obj = getObj(someid);
if(obj != null) {
deleteObj(someId);
}
Or just:
deleteObj(someId);
?
From a performance standpoint you will likely be better off just making an attempt at deleting a record based on id versus trying to fetch the record and then going back to the database to delete it. It's always good practice to limit the number of transactions on your database.
DELETE FROM TableName
WHERE Id = @Id
You will know if you deleted any records based on the row count that is returned from a query similar to the one above.
精彩评论