Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 30th, 2006, 03:44 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
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
========================
Reply With Quote
  #2 (permalink)  
Old May 31st, 2006, 09:56 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Try this:
ALTER TABLE Table1
ALTER COLUMN Column1 int NOT NULL IDENTITY
Reply With Quote
  #3 (permalink)  
Old June 1st, 2006, 01:20 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I get:

Incorrect syntax near the keyword 'IDENTITY'

Reply With Quote
  #4 (permalink)  
Old June 1st, 2006, 01:26 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
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?

Reply With Quote
  #5 (permalink)  
Old December 29th, 2006, 12:46 PM
sal sal is offline
Friend of Wrox
 
Join Date: Oct 2003
Location: Clarksville, TN, USA.
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
Reply With Quote
  #6 (permalink)  
Old January 5th, 2007, 11:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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 liz@trinityholdings.co.za Access 2 July 29th, 2003 03:06 AM



All times are GMT -4. The time now is 11:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.