Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Add A Column To A Table With SQL On A MySQL Database

Code

ALTER TABLE table_name ADD COLUMN column_name details_for_column;

Examples:

Code

ALTER TABLE samples ADD COLUMN id_number INT;

Code

ALTER TABLE genres ADD COLUMN genre VARCHAR(100) NOT NULL UNIQUE;

Note that if you set unique, the values in the table have to be unique already. Same goes for `not null`.

- These are for mysql. - Need to test with other database. - I'm using `ADD COLUMN column_name`. You can remove `COLUMN` and call `ADD column_name` as well, but I like the more explicit version.