Is there a way to migrate existing database with all tables and relations to use SQL Server auto ids instead of Nhibernate (hilo) ids?
We have a .NET application which uses NHibernate. But the problem is, we are running out of int
.
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 ids
, which makes situation worse.
For example, we have a database of 3 tables:
dbo.Users
dbo.RegistrationResults
dbo.UserNotes
Tables:
dbo.Users
Id
int (Primary)Email
nvarchar(255)RegistrationResultFk
int (Foreign Key)
dbo.RegistrationResults
Id
int (Primary)ValidationOutcome
nvarchar(255)
dbo.UserNotes
Id
int (Primary)Message
nvarchar(255)RegistrationResultFk
int (Foreign Key)
And data populated like this:
dbo.Users
Id | RegistrationResultFk | |
---|---|---|
1 | test@gmail.com | 2 |
4 | test2@gmail.com | 5 |
dbo.RegistrationResults
Id | ValidationOutcome |
---|---|
2 | Awaiting confirmation |
5 | Confirmed |
dbo.UserNotes
Id | Message | RegistrationResultFk |
---|---|---|
3 | it's a test | 2 |
6 | it's a test 2 | 5 |
We want data after migration to look like:
dbo.Users
Id | RegistrationResultFk | |
---|---|---|
1 | test@gmail.com | 1 |
2 | test2@gmail.com | 2 |
dbo.RegistrationResults
Id | ValidationOutcome |
---|---|
1 | Awaiting confirmation |
2 | Confirmed |
dbo.UserNotes
Id | Message | RegistrationResultFk |
---|---|---|
1 | it's a test | 1 |
2 | it's a test 2 | 2 |
id
s in the database to remove "gaps" created by nhibernate and give you more room still using theint
datatype, and update all foreign keys using these values? Or can you accept a change to the id datatype fromint
to abigint identity
column (where the data type change would affect client applications but is much easier to do on the database side)?int
id
. But thisint
is shared between tables. For example. I have tabledbo.users
. It has a row, with id 1. And I have another table calleddbo.permissions
which starts withid
2. It is, because hilo uses sharedid
. So that's why it's very scary. Because we have 20+ tables which uses sharedid
and it's increasing very fast.