How to manipulate MySQL tables

This page gives some simple tasks to do with manipulating the tables in a MySQL database.

Find what columns are in a table

To find what columns a table tablename contains,
SHOW COLUMNS IN tablename;

Add a column to a table

To add a new column called colname with a boolean type to a table called name,

Delete a column

To remove a column called colname from a table name,
mysql> ALTER TABLE name DROP colname;

Change the order of columns in the table

To put an existing column called colname with the type INTEGER as the first column in the table, use
mysql> alter table tablename modify colname integer first;
To put a column called col1 with the type INTEGER after col2 in the ordering, use
mysql> alter table tablename modify col1 integer after col2;
The type of col2 does not need to be specified.]]>
Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. / Privacy / Disclaimer