proper way to delete album and its media and sub album and its media
what would be proper way to delete albums hierarchical data with its media.
should i just start looping and find all the sub album id and delete thous and make query to delete all the media belonging to that album id.
that will be loads of query execution if data is 开发者_如何学编程alot or albums are alot for a user. what your device is on this.
my database structure:
**album**
album_id
name
parent_id
**media**
media_id
album_id
name
DELETE
FROM albums,
media
WHERE media.albumID = albums.albumID
AND (albums.parentID = ? or albums.albumID = ?)
That is the simplest approach, assuming you don't have triggers or relations defined in your data. Without knowing more about your specific database structure its hard to give a better answer; however, as with other situations, you are better off doing this as a single SQL statement. Why? It preserves your data integrity, otherwise you have to issue locks on the various tables while your software manually deletes specific entries (which is also a solution, but barring knowing more, not one I'd recommend).
精彩评论