Convert INT to VARCHAR

All,

I have a populated table with SSN ' column as INT data type . Is it possible to convert the " SSN " column and the data in the column to VARCHAR (#).

ALTER TABLE Table1
 MODIFY SSN varchar(9);

Will this work?

Thank!

Any help is appreciated!

+3
source share
1 answer
alter table Table1
  alter column SSN varchar(9);

You can run a quick test to make sure it saves the data.

create table #data(
  ssl int
)

insert into #data values(1)
insert into #data values(2)
insert into #data values(3)
insert into #data values(4)

select * from #data

alter table #data
  alter column ssl varchar(9)

select * from #data

And there are never any problems with backups before doing such things. Even a quick insert into another table works if it is not a huge amount of data.

+8
source

All Articles