Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 adding auto_increment id column

Author  Topic 

jmarksamer
Starting Member

2 Posts

Posted - 2007-08-17 : 14:38:23
i'm trying to add an 'id' column that will auto_increment in a table that i've set up in sql enterprise server. i tried using the code:

ALTER TABLE tablename ADD id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST

however, i get the following error:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'ID'.

could someone please help (ASAP!!!) with how to fix this.
thanks in advance for any help.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-17 : 14:50:48
ALTER TABLE tablename
ADD id int identity(1,1) not null
,CONSTRAINT pk_id Primary key (id asc)

Jim
Go to Top of Page
   

- Advertisement -