AAB
AAB

Reputation: 1653

UPDATE or DELETE in mysql

I have gone through this post I have a Database that has id,password,date of birth.

id|name|password|dob
1 |avi |vx1     |2013-1-1

I have a few questions lets say a user wishes to change his/her password then what is the correct way to go should I use UPDATE user SET password='pusheen' WHERE id=1 or Should I delete the value first and then Insert the value in the column.

(I understand password should be inserted in database in encrypted form but I`m newbie learning so saving it as plain text.)

The link above suggests not to use update is the case in above link similar to mine?

The same goes for any other field lets say I wish to have name field as blank/null.

whats the command to delete a field say name where id=1 and insert again? each time I try to delete I end up deleting the whole row.

is use of UPDATE user SET name=NULL WHERE id=1 not the correct way?

Upvotes: 0

Views: 1346

Answers (2)

Haji
Haji

Reputation: 2077

You can delete the record simply by using

delete from user where id = 1

but if you are going to update the user password,then you don't need to delete and insert as new one.. you can simply use the update statement like

UPDATE user SET password='pusheen' WHERE id=1

If you want to insert new user, then only goes to insert statement like

  insert into user(id,name,password,dob) values
  (2,'name','password','11/11/1985')

Aside: You should not store passwords as plain text ever. This answer shows the simplest method that you will not have a problem using. It's better than nothing.

Upvotes: 3

Florin
Florin

Reputation: 6169

The right way is to UPDATE because in that table you will have multiple columns and you don't want to miss something.

UPDATE user SET name='username' WHERE id=1

Upvotes: 2

Related Questions