July 14, 2010 at 11:27 am
I'm trying to alter a table by making an existing column an identity column. If I try to do this by right clicking on the table and selecting Modify, I get a timeout expired message when saving my change. If I try to do this by writing an alter query I get an incorrect syntax message.
alter table dbo.mytable alter column mycolumn [int] identity(1, 1) not null
Any tips on how I can successfully accomplish this?
July 14, 2010 at 12:30 pm
how many records are in the table? The timeout is probably happening because SQL is creating a tmp table and then copying the data from the main table to the tmp table. if you go through the modify table like you did, you can hit script to see what it is doing. You can also run
alter table myTable add field2 int identity(1,1) not null
Why are you adding an identity column anyway?
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
July 14, 2010 at 8:21 pm
The column should have been identity in the first place, but it wasn't. Way too many rows in table and definitely timing out because of this. Took a different plan of action and created a new column instead - not how I wanted to do it, but it works!
July 15, 2010 at 1:56 am
K Currie (7/14/2010)
I'm trying to alter a table by making an existing column an identity column.
There is a super-quick way if the existing column is currently defined as NOT NULL. Is that the case?
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
July 15, 2010 at 9:25 am
yes - that's the case, but I obviously dont want the existing number to change.
Please share so I'll know for next time.
July 15, 2010 at 10:20 pm
K Currie (7/15/2010)
yes - that's the case, but I obviously dont want the existing number to change. Please share so I'll know for next time.
Please see the following post on a thread a few months ago:
http://www.sqlservercentral.com/Forums/FindPost928840.aspx
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
July 15, 2010 at 10:43 pm
You might also be interested in voting for this Connect item by Adam Machanic:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
July 17, 2010 at 2:03 am
Reseeding a Column has not been easy for me. Its very time consuming.
We Use This:-
alter table MyTable drop column [ID]
alter table MyTable add id int identity not null
We normally have to do this when we take any table across to another database. Because Identity get lost if we migrate a table to other database.
Does anyone know a better way of doing this?
July 17, 2010 at 3:18 am
See the link I posted two posts back.
edit: here it is again, just to make it easy:
http://www.sqlservercentral.com/Forums/FindPost928840.aspx
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply