Sunday, August 17, 2008

MySql insert, update, AND delete

MySql Insert, Update, and Delete

Insert statement
insert into tableName (column1, column2...) values (value1, value2 ...)
insert into tableName (id, name) values (null, 'John')
* The null can be use in the column which is auto_increment so that the database will auto assign new id for the next data.

Update statement
update tableName set column1=value1, column1=value2 where column=idvalue
update tableName set name='johnson' where id=5
*From here, it will change the name of data id number 5 to 'johnson'

Delete statement
delete from tableName where column=idvalue
delete from tableName where id=5
*It will delete the row for id number 5