MySQL Alterations



Altering Table Structure


To alter a table after creation, we need to use the ALTER TABLE command. ALTER TABLE allows us to change the structure of a given table. This command typically works in conjunction with optional followup commands. Some of these include:

Updating Data


The UPDATE command allows users to change the values of the data in a table, after it has been entered. The most common additional command is SET. SET allows users to set the values in a given column. Without any other information, SET will change the entire column. To affect only certain records, the SET command can be combined with a WHERE clause, limiting the rows that are altered.
UPDATE tblName SET colName=2;  //changes all values in colName to 2
UPDATE tblName SET colName=2 WHERE gender='F'; //changes all values in colName to 2 only if the gender value is 'F'

We can also delete an entire record, without altering other entries. To do this, we use the DELETE command as seen below:
DELETE FROM tblName where id=3; //deletes the record with id=3 in tblName