Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Jonathan [Darka] 28-Mar-13 6:10am    
What have you tried so far?

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.
 
Share this answer
 
Comments
Darsh_Basha 28-Mar-13 7:59am    
Thx
SQL
--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
 
Share this answer
 
Comments
Darsh_Basha 28-Mar-13 7:59am    
Thx
Karruksen 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900