Wednesday, March 11, 2020
Add a MySQL Column Using the Add Column Command
Add a MySQL Column Using the Add Column Command The command add column is used to add an additional column to any given MySQL table. To do this, you must specify the column name and type. Note: The add column command is sometimes referred to as additional column or new column. How to Add a MySQL Column Adding a column to an existing table is done with this syntax: alter table add column [new column name] [type]; Heres an example: alter table icecream add column flavor varchar (20) ; What this example would end up doing is adding the column flavor to the table icecream, just as it says above. It would be in the database varchar (20) format. Know, however, that the column clause is not required. So, you could instead use add [new column name]..., like this: alter table icecream add flavor varchar (20) ; Adding a Column After an Existing Column Something you may prefer to do is add a column after a specified existing column. So, if youd like to add the column flavor after one called size, you could do something like this: alter table icecream add column flavor varchar (20) after size; Changing a Column Name on a MySQL Table You can change a columns name with the alter table and change commands. Read more about that in the How to Change a Column Name in MySQL tutorial.
Subscribe to:
Posts (Atom)