title: How to migrate data to another table
body: <p>Hi I am in need of a script that Updates the rows on a table from another table based on an ID and after that it deletes the from the second table the data it  copied.</p>
  
  <p>This are the tables I have</p>
  
  <pre><code>Documents
  --------
  DocumentID(PK)
  RealFileName
  FileName
  
  ImageDocuments
  --------------
  ImageDocumentId(PK)
  DocumentId(FK)
  OriginalFileName
  StorageFileName
  </code></pre>
  
  <p>Mapping beetween the two tables is One to One.</p>
  
  <p>At the moment I have the script that updates the table but I do not know how to proceed to delete the values from documents table.This is what I have so far:</p>
  
  <pre><code>UPDATE [dbo].[ImageDocuments]
  SET [dbo].[ImageDocuments].[OriginalFileName] = d.FileName,
      [dbo].[ImageDocuments].[StorageFileName] = d.RealName
  FROM [dbo].[ImageDocuments] as fu, 
       [dbo].[Documents] as d
  WHERE fu.DocumentID = d.DocumentID
  </code></pre>
  
  <p>How can I delete from the documents table the rows that were added to the ImageDocuments table?</p>
  
  <p><strong>UPDATE</strong>
  I create a delete query can anyone please validate if this will work corectly:</p>
  
  <pre><code>DELETE [dbo].[Documents]
  FROM [dbo].[ImageDocuments] as fu
  INNER JOIN [dbo].[Documents] as d ON d.DocumentID = fu.DocumentID
  </code></pre>