0

I have two tables called 'Images' and 'ImagesMSCV'. Both these tables contain the two columns 'MicrosoftId' and 'ImageId'. Right now the tables look like...

        Images                            ImagesMSCV
MicrosoftId | ImageId               MicrosoftId | ImageId
   null         234                     467        234 
   null         172                     512        172 
   null         376                     327        376 
   etc          etc                     etc        etc

So I'm trying to copy the 'MicrosoftId' column from 'ImagesMSCV' into the same column in 'Images'. To do this, I wrote the following SQLite statement...

UPDATE Images
  SET MicrosoftId =
    (SELECT MicrosoftId FROM ImagesMSCV
     WHERE ImagesMSCV.ImageId = Images.ImageId);

...however when I run this statement, my database just crashes. I don't know what's wrong with it?

EDIT: Apparently the database just stops responding because the UPDATE is taking so long. Any idea how to improve performance?

aadu
  • 3,196
  • 9
  • 39
  • 62
  • `UPDATE Images SET MicrosoftId = (SELECT MicrosoftId FROM ImagesMSCV WHERE ImagesMSCV.ImageId = Images.ImageId) WHERE ImageId = 234` It should complete. If yes, then your query is correct. – Lukasz Szozda Sep 19 '17 at 15:04

1 Answers1

0

For each row in the Images table, the database has to look up the corresponding row in the ImagesMSCV table. Each such lookup requires a full table scan, except when there is an index on that column:

CREATE INDEX xxx ON ImagesMSCV(ImageId);
CL.
  • 173,858
  • 17
  • 217
  • 259
  • May I ask why you downvoted my answer without leaving any comment? The question was a bit unclear at the beginning and my answer just show possible steps. – Lukasz Szozda Sep 22 '17 at 16:46