Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 SQL
hi
 
i get this Error
Incorrect syntax near 'int'
 
when i modify my table
 
ALTER TABLE upload  ALTER  COLUMN MODIFY id int IDENTITY(46,1)
 
help me .
Posted 28-Mar-13 1:08am
Comments
Jonathan [Darka] at 28-Mar-13 6:10am
   
What have you tried so far?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Please this here for correct syntax of ALTER COLUMN statement.
 
Moreover, you cannot alter a column that is used as primary key ; you have to create a brand new table with correct columns, transfer data from old table to new one, delete old table and rename new one. The process could involve to suppress/recreate some foreign keys in other tables, also. Can be a tough task depending on the size of your database.
 
Hope it makes sense.
  Permalink  
Comments
Darsh_Basha at 28-Mar-13 7:59am
   
Thx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

--create test table

create table table1 (col1 int, col2 varchar(30))
 
insert into table1 values (100, 'olddata')
 

 
 --add identity column

alter table table1 add col3 int identity(1,1)
 
GO
 

 
--rename or remove old column

exec sp_rename 'table1.col1', 'oldcol1', 'column'
 
OR
 
alter table table1 drop column col1
 
--rename new column to old column name

exec sp_rename 'table1.col3', 'col1', 'column'
 
GO
 

 
--add new test record and review table

insert into table1 values ( 'newdata')
 
select * from table1
  Permalink  
Comments
Darsh_Basha at 28-Mar-13 7:59am
   
Thx
Karruksen at 5-Apr-13 0:28am
   
Pls Accept this answer..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 28 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100