Tuesday, November 5, 2019
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:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.