Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2006, 03:44 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default Alter Column

Not sure why but I can't seem to figure out how to make an integer column an identity AFTER the table has been created.

I have tried this:

ALTER TABLE Table1
ALTER COLUMN Column1 int IDENTITY NOT NULL
GO

And various iterations. No luck. Maybe i'm just a bit foggy due to the long weekend, but does anyone know how this is done?

Thanks...

Scott

__________________
========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
 
Old May 31st, 2006, 09:56 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Try this:
ALTER TABLE Table1
ALTER COLUMN Column1 int NOT NULL IDENTITY
 
Old June 1st, 2006, 01:20 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I get:

Incorrect syntax near the keyword 'IDENTITY'

 
Old June 1st, 2006, 01:26 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

what version of sql server are you using? I tried this on SQL Server 2005 and didn't get an error. Are you using sql express?

 
Old December 29th, 2006, 12:46 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Posts: 702
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you have data on your table, you must give it a starting value and an increment value. For instance if you have numbers up to 1000 and you want to increment by 1 you do this:

Identity (1000,1)



Sal
 
Old January 5th, 2007, 11:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes, you have been missing the Identity seed and increment values... That is why you have not been getting it right.

Cheers.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
alter add puzzle: Invalid column name JL1024 SQL Server 2000 11 June 11th, 2013 04:59 PM
Alter a column as identity for table kasanar SQL Server 2000 5 July 6th, 2005 08:44 AM
Alter Column - Default Value sasidhar79 SQL Server 2000 2 January 18th, 2005 07:30 AM
Alter Default on a Column Gert SQL Server 2000 4 November 28th, 2003 08:58 AM
Alter Table - Add Column [email protected] Access 2 July 29th, 2003 03:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.