June 17, 2003 at 8:14 am
I get the same error, can't find in BOL why the syntax error. Anyway, what about this:
-- First add an identity column...
ALTER TABLE MyTable
ADD MyNewIdentityColumn INT NOT NULL IDENTITY(1,1)
GO
-- Next, throw the old values into the new identity column
UPDATE MyTable SET MyNewIdentityColumn = MyOldIntColumn
GO
-- Next, drop old column
ALTER TABLE MyTable
DROP COLUMN MyOldIntColumn
GO
Edited by - jpipes on 06/17/2003 08:14:25 AM
June 17, 2003 at 8:17 am
Thanks Jay,
It seems there is no easy way.
Tom
June 17, 2003 at 8:22 am
As a final note, you may want to go into Enterprise Manager and change the table in the Design View, then click Save Script button and see what SQL internally thinks is the best method for handling this...Sometimes this technique is useful in figuring out some of the trickier DDL constructs...
Good luck!
June 17, 2003 at 8:55 am
Ok, I went back to BOL and looked at the syntax.
The IDENTITY option is only available if you are adding a column. ALTER COLUMN allows you to add or drop ROWGUIDCOL but not IDENTITY.
EM does it by creating a new table with the IDENTITY property, copying the data to it, dropping the old table, and renaming the new table. That's what your script will probably reveal.
K. Brian Kelley
http://www.truthsolutions.com/
Author: Start to Finish Guide to SQL Server Performance Monitoring
http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1
K. Brian Kelley
@kbriankelley
June 17, 2003 at 8:59 am
Brian, jay,
thanks for your help
Tom
Viewing 5 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply