0

単純なタグ関係を保存していますが、タグを削除するためのより良い方法は何でしょうか?

私が知っている2つの方法:

  1. SELECT tag FROM content_tags WHERE content_id = 10
  2. phpを使用して、結果を提供された新しいタグと比較します。データベースの結果に新しいタグにないタグがある場合は、そのタグに対して削除クエリを実行します。
  3. 残りのタグは新しいか、すでに存在しているので、INSERT INTO content_tags ... ON DUPLICATEKEYUPDATEを使用します

または単に:

  1. DELETE FROMcontent_tagsFROMタグWHEREcontent_id= 10
  2. 各タグを挿入します(このcontent_idのタグはこの時点ですでに削除されているため、ここでON DUPLICATE KEY UPDATEを使用する必要はありません)

I'm current doing the first method, but the 2nd way seems to be much less of a hassle. But I'm not sure if it's "bad" or inefficient to use delete in this fashion. Or if you have a better method feel free to share.

4

1 に答える 1

0

You could adjust the first method to do also not do the inserts on tags that already exist. But it could (and probably will) still result in more queries then the second method, especially if you combine those insert statements in a single query.

//small example :)

INSERT INTO content_tags
(content_id, tag_id)
VALUES
(1,1),
(1,2),
(1,3);
于 2011-02-10T07:58:15.187 に答える