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 tabletablename
contains,
SHOW COLUMNS IN tablename;
Add a column to a table
To add a new column calledcolname
with a boolean type to a table called name
,
mysql> ALTER TABLE name ADD COLUMN colname BOOLEAN;
Delete a column
To remove a column calledcolname
from a table name
,
mysql> ALTER TABLE name DROP colname;
Change the order of columns in the table
To put an existing column calledcolname
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-2024. All
rights reserved.
For comments, questions, and corrections, please email
Ben Bullock
(benkasminbullock@gmail.com).
/
Privacy /
Disclaimer