Can't "update" to identity insert

Posts   
 
    
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 21-Jun-2010 07:18:00   

LLBL3 generates this:


ALTER TABLE [dbo].[Page] 
    ALTER COLUMN [PageId] [int] IDENTITY (1,1) NOT NULL
GO

However, it appears it can't be done (it certainly doesn't execute).

http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032/

(This is MS SQL)

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 21-Jun-2010 09:23:17   

We'll check this out and get back to you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Jun-2010 09:47:03   

Hmm, odd we did change the DDL SQL script to generate a comment instead of the statement as indeed this can't be done. I think this happens because something else changes in the column and it generates the 'identity' statement. Am I correct in that you changed something else for the column (e.g. nullability) ?

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 21-Jun-2010 10:32:59   

I see the mistake in our template: the template does emit a comment instead of a statement when the identity was reset, but not when it was set. Silly mistake. I've altered the template in such a way that when the Identity flag was changed, it now always emits the comment, either when it was set or reset.

The code in the template stays the same though. We just emit the following comment. I've added your url to the comment we already had in the template:


    -- Identity constraint was changed on field '<%=field.FieldName%>'. However SQL Server doesn't allow changing this in SQL. 
    -- This means that you have to do this manually by creating a new temporary column, copy over all data and then remove 
    -- the column (cumbersome, due to FK constraints). Another, probably less cumbersome way, is to do this through SSMS, which 
    -- does the handling for you. Example of how to do it manually:
    -- http://stackoverflow.com/questions/702745/sql-server-how-to-drop-identity-from-a-column
    -- Discussion about this issue on MS' forums:
    -- http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032/

So we know the template crashes, but there's no way around that, so we emit a comment at that spot with information what to do next as that's what we can do unfortunately. We've investigated if this is doable through system table manipulation but couldn't find anything there. It's a little silly why this can't be done through DDL but alas, there are more stupid things to be found in sql server...

Frans Bouma | Lead developer LLBLGen Pro
worldspawn avatar
worldspawn
User
Posts: 321
Joined: 26-Aug-2006
# Posted on: 24-Jun-2010 02:18:20   

Yes another favourite is not being able to add a new column at a specific index. I guess I'm not modifying the identity-ness of a field that much (hardly ever actually). Thanks.

This feature where I can generate update scripts - how smart is that? Will it generate (sql) updates from when it was last generated or just the changes made since you opened the file?

If it generates changes since the DDL was last generated that would be awesome. It means we can manage collaborative db development (or LLBL development i guess it has become) in a way this isn't very fragile.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 24-Jun-2010 10:52:38   

This feature where I can generate update scripts - how smart is that? Will it generate (sql) updates from when it was last generated or just the changes made since you opened the file?

If it generates changes since the DDL was last generated that would be awesome.

From the last generated Update simple_smile