Skip to main content

Posts

Showing posts from July, 2010

Grailsify legacy ms sql database

I had a problem. I'm developing using grails but my constraint is that I have to use a legacy ms sql database that was created by importing data from excel to access to ms sql. Thus the tables do not have any id field or primary key. And not only that, once I've done my work on my pc, and I do a full dump onto the server using MS own "SQL Server Import and Export Wizard 2008" it does not retain the identity property of the id field (that's auto-increment for all you lucky mysqlers). So when grails try to create a new record it fails. So so sad. But after a few days of depressive wanderings I decided to be a man and solve this. So here's the script in full, of how you would automatically create an id if the table does not have it yet, and if already has, will do the whole recreate process to make the id an identity again. Hope it would benefit someone.

declare @tablename varchar(1000),@importnew nvarchar(1000),@addconstraint nvarchar(1000),@dropold nvarchar(100…