开发者

Database: get and delete or just delete?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜