Question: I need to update a table data in database using RAILS migrations. 

```
Sample:
Table: Table_A(Col_A(number), Col_B(varchar),...)
Query: UPDATE Table_A SET Col_B = "XXX" where Col_B = "YYY"

```

What would be the best way to do this using RAILS Migrations. I am not even sure if RAILS migrations is the way to go for updating data in database. Any explanation would be helpful.

Answer: 
You can do like this:

```
 class YourMigration < ActiveRecord::Migration
   def up    
     execute('UPDATE Table_A SET Col_B = "XXX" where Col_B = "YYY"')
   end

   def down
   end
 end

```

Or:

```
 class YourMigration < ActiveRecord::Migration
   def up   
     update('UPDATE Table_A SET Col_B = "XXX" where Col_B = "YYY"')
   end

   def down
   end
 end

```
```
ActiveRecord::Base.connection.execute("update Table_A set Col_B = 'XXX'  where Col_B = 'YYY')

```