Changing data type from decimal to Int In SQL Server 2008 -


in table id column has been set decimal(10,0) previously. can see useless , change int type.

however table contains data , keep data. id primary key , been referenced other tables. worth mentioning column auto-increment.

i wonder whether possible alter decimal int without affecting existing data in table?

you need first drop foreign key constraint referencing table drop primary key constraint alter column datatype int add primary key once again.

for every referenced table execute line

 1. alter table foreignkeytablename drop foreign key constraintname;      alter table foreignkeytablename alter column refcolumnname int ; 

for primary table

  1. alter table tablename  drop constraint primary key constraint name       2. alter table tablename alter column id int        3. alter table tablename add  primary key (id) 

add foreign key every referenced table

alter table foreignkeytablename add constraint constraitname  foreign key (fk_columnname) references primarykeytablename(pk_columnname) 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -