title: Create a unique primary key (hash) from database columns
body: <p>I have this table which doesn't have a primary key.</p>
  
  <p>I'm going to insert some records in a new table to analyze them and I'm thinking in creating a new primary key with the values from all the available columns. </p>
  
  <p>If this were a programming language like Java I would:</p>
  
  <pre><code> int hash = column1 * 31 + column2 * 31 + column3*31 
  </code></pre>
  
  <p>Or something like that. But this is SQL.</p>
  
  <p>How can I create a primary key from the values of the available columns? It won't work for me to simply mark all the columns as PK, for what I need to do is to compare them with data from other DB table. </p>
  
  <p>My table has 3 numbers and a date.</p>
  
  <p><strong>EDIT <em>What my problem is</em></strong></p>
  
  <p>I think a bit more of background is needed.  I'm sorry for not providing it before. </p>
  
  <p>I have a database ( dm ) that is being updated everyday from another db ( original source ) . It has records form the past two years. </p>
  
  <p>Last month ( july )  the update process got broken and for a month there was no data being updated into the dm. </p>
  
  <p>I manually create a table with the same structure in my Oracle XE, and I copy the records from the original source into my db ( myxe ) I copied only records from July to create a report needed by the end of the month. </p>
  
  <p>Finally on aug 8 the update process got fixed and the records which have been waiting to be migrated by this automatic process got copied into the database ( from originalsource to dm ). </p>
  
  <p>This process does clean up from the original source the data once it is copied ( into dm ). </p>
  
  <p>Everything look fine, but we have just realize that an amount of the records got lost ( about 25% of july )  </p>
  
  <p>So, what I want to do is to use my backup ( myxe )  and insert into the database ( dm ) all those records missing. </p>
  
  <p>The problem here are:</p>
  
  <ul>
  <li>They don't have a well defined PK.</li>
  <li>They are in separate databases. </li>
  </ul>
  
  <p>So I thought that If I could create a unique pk from both tables which gave the same number I could tell which were missing and insert them. </p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>So I did the following in my local environment:</p>
  
  <pre><code>select a.* from the_table@PRODUCTION a , the_table b where
  a.idle = b.idle and 
  a.activity = b.activity and 
  a.finishdate = b.finishdate
  </code></pre>
  
  <p>Which returns all the rows that are present in both databases ( the .. union? )  I've got 2,000 records.</p>
  
  <p>What I'm going to do next, is delete them all from the target db and then just insert them  all s from my db into the target table</p>
  
  <p>I hope I don't get in something worst : - S : -S </p>