【发布时间】:2017-11-25 03:10:48
【问题描述】:
这是我的情况:
• I have a table of users <br><br>
• I have a table of movies <br><br>
• I have a table of user_movies that associates users to movies that stores a frequently changing "score" column on each record.<br><br>
• I need to be able to bulk update the user_movies table for speed and to do so I believe I need a unique index to be able to pull off bulk updates like this.<br><br>
• Considering each user_movie combination is unique, would it be possible to do
使用(User_id--->) uid_mid (<----movie_id) 之类的东西作为唯一标识符?如果是这样,如何将现有表转换为这个?
【问题讨论】:
-
我不确定我是否理解您的要求,但您知道您可以在两列上创建索引,对吧? “CREATE UNIQUE INDEX myindex ON user_movies(user_id, movie_id)”(如果您始终在针对该表的所有查询中指定两列,则列的顺序无关紧要)。
-
如何使用 2 列共同构成唯一索引但不单独进行批量更新?
-
我想我在这里误解了一些东西。您如何进行批量更新?
-
我使用 $this->db->update_batch('extra_config', $updateData,'id'); } 在 Codeigniter 中,它需要一个唯一的 id 来进行这种批量更新。
-
我发现这个解包了 CodeIgniter 正在做的更具体的事情:' // 产生: // UPDATE
mytableSETname= CASE // WHENtitle= 'My title' THEN ' My Name 2' // WHENtitle= 'Another title' THEN 'Another Name 2' // ELSEnameEND, //date= CASE // WHENtitle= 'My title' THEN 'My date 2' // WHENtitle= 'Another title' THEN 'Another date 2' // ELSEdateEND // WHEREtitleIN ('My title','Another title')'
标签: php mysql sql unique unique-index