Question : How can I change the identity property of a column without setting the wrong seed?

I have a column which should have been set as an Identity column but was not.  I need to change the value of the seed to the next available ID.  I have tried as per the sample below which generates an error - is there a way to do this, ideally in one line?

Chris Bray
Code Snippet:
1:
ALTER TABLE TaxCodes ALTER COLUMN [TaxCodeId] BIGINT NOT NULL IDENTITY ((SELECT Max(TaxCodeId)+1 FROM TaxCodes), 1);

Answer : How can I change the identity property of a column without setting the wrong seed?

indeed, you are correct. I missed that this feature is possible visibly since sql 2005, in prior versions it did not work that way.
so, good day, I learned something new!

for your question, you won't come around dynamic sql to first query the value, or to reseed (which is what I woud do):
http://technet.microsoft.com/en-us/library/ms176057.aspx

without the reseed value specified, it will take the "max" value already stored...
1:
2:
ALTER TABLE TaxCodes ALTER COLUMN [TaxCodeId] BIGINT NOT NULL IDENTITY (1, 1);
DBCC CHECKIDENT (TaxCodes, RESEED)
Random Solutions  
 
programming4us programming4us