Bright Java Tutorial

is brought to you by DoITBright LLC

MySQL

Alter Table In MySQL

Here is a scenario. We have an existing database table. It has beed working for us for a very long time. This means, it contains tons of data. Then, a requirement came to add an additional column to that specific table. Lets use use the database tables we created in the previous lesson.
  ALTER TABLE ACCOUNT ADD FULL_NAME VARCHAR(60);
                            
By executing the above code, we added a column 'FULL_NAME' with a data type of 'VARCHAR'. This is how you will verify how your table structure is.
  DESC ACCOUNT;
                            
If you wish to remove a database table column, the LATER TABLE statement is also what you need to use. Here is an example of how you will do it.
  ALTER TABLE ACCOUNT DROP COLUMN FULL_NAME;
                            
If you pay attention to the above code, we needed to mention the keyword 'COLUMN' after we mentioned the keyword 'DROP'. The 'COLUMN' is then followed by the column name we wish to remove. Verify your table again.
  DESC ACCOUNT;
                            



Back    Next