updating only one column in a table

hi all,

           im having a table called employees in db.the table hava five
columns as

1.username
2.password
3.firstname
4.lastname
5.mailid.

          in this i want to update only password column.how to do
it.people knows it please help me.

hi all,

          im having a table called employees in db.the table hava five
columns as

1.username
2.password
3.firstname
4.lastname
5.mailid.

         in this i want to update only password column.how to do
it.people knows it please help me.

ActiveRecord does have an update_attribute method, however (despite
the name) it saves the whole record. You can probably force it to save
less if you had loaded the record with a more restrictive :select. Or
you can drop down a level and use Employee.update_all

Fred

u can do update like
Employee.update_attributes(:password => params[:employee][:password])

:slight_smile:

It's also worth nothing that the next release of Rails (2.1) will do
just the kind of save you're asking about. If this is not an
immediate production demand it may be worth coding with the standard
methods in the short term and absorb the penalty hit and getting the
functionality for free when 2.1 is released.

Karthikragunath Bhavani wrote:

hi all,

           im having a table called employees in db.the table hava five
columns as

1.username
2.password
3.firstname
4.lastname
5.mailid.

          in this i want to update only password column.how to do
it.people knows it please help me.

If nothing else helps, you can do this,

  Employee.connection.execute("update employees set
password='superseekret' where id=123")

(Look up some means to prevent SQL-Injection.)

Stephan