Change the Datatype of Column

--

Int to String:

To change the data type of a column in SQL from string to int, you can use the ALTER TABLE statement along with the MODIFY COLUMN clause. Here’s an example syntax:

ALTER TABLE table_name MODIFY COLUMN column_name INT;
ALTER TABLE users MODIFY COLUMN tax_rate INT;

OR

alter table table_name alter column column_name TYPE INTEGER USING ( 0 || '')::int;
alter table users alter column tax_rate TYPE INTEGER USING ( 0 || '')::int;

Replace table_name with the name of your table and column_name with the name of the column you want to change. The INT keyword specifies the new data type.

It’s recommended to backup your data before making any changes to your database schema.

--

--

BharteeTechRubyOnRails
BharteeTechRubyOnRails

Written by BharteeTechRubyOnRails

Ruby on Rails Developer || React Js || Rspec || Node Js

No responses yet