title: Migrate from NHibernate ids (hilo) to SQL auto ids in SQL Server
body: <p>Is there a way to migrate existing database with all tables and relations to use SQL Server auto ids instead of Nhibernate (hilo) ids?</p>
  <p>We have a .NET application which uses NHibernate. But the problem is, we are running out of <code>int</code>.</p>
  <p>I know that this requires tables recreation with new ones which have ids set as auto incremented. Is there a easy way to migrate. For example some sort of query which will replicate tables, keep relations, but now with SQL Server ids instead of hilo ids. Biggest problem of hilo, it's using shared <code>ids</code>, which makes situation worse.</p>
  <p>For example, we have a database of 3 tables:</p>
  <ul>
  <li><code>dbo.Users</code></li>
  <li><code>dbo.RegistrationResults</code></li>
  <li><code>dbo.UserNotes</code></li>
  </ul>
  <p>Tables:</p>
  <p><code>dbo.Users</code></p>
  <ul>
  <li><code>Id</code> int (Primary)</li>
  <li><code>Email</code> nvarchar(255)</li>
  <li><code>RegistrationResultFk</code> int (Foreign Key)</li>
  </ul>
  <p><code>dbo.RegistrationResults</code></p>
  <ul>
  <li><code>Id</code> int (Primary)</li>
  <li><code>ValidationOutcome</code> nvarchar(255)</li>
  </ul>
  <p><code>dbo.UserNotes</code></p>
  <ul>
  <li><code>Id</code> int (Primary)</li>
  <li><code>Message</code> nvarchar(255)</li>
  <li><code>RegistrationResultFk</code> int (Foreign Key)</li>
  </ul>
  <p>And data populated like this:</p>
  <p><code>dbo.Users</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Email</th>
  <th>RegistrationResultFk</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>test@gmail.com</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>test2@gmail.com</td>
  <td>5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><code>dbo.RegistrationResults</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>ValidationOutcome</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>2</td>
  <td>Awaiting confirmation</td>
  </tr>
  <tr>
  <td>5</td>
  <td>Confirmed</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><code>dbo.UserNotes</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Message</th>
  <th>RegistrationResultFk</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>3</td>
  <td>it's a test</td>
  <td>2</td>
  </tr>
  <tr>
  <td>6</td>
  <td>it's a test 2</td>
  <td>5</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><em><strong>We want data after migration to look like:</strong></em></p>
  <p><code>dbo.Users</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Email</th>
  <th>RegistrationResultFk</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>test@gmail.com</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>test2@gmail.com</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><code>dbo.RegistrationResults</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>ValidationOutcome</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Awaiting confirmation</td>
  </tr>
  <tr>
  <td>2</td>
  <td>Confirmed</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><code>dbo.UserNotes</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Message</th>
  <th>RegistrationResultFk</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>it's a test</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>it's a test 2</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>