All SQL Commands for Table

A list of common commands that can be executed on a SQL table to change its structure, with common syntax and example.

Commands for accessing content using SELECT or adding a row using INSERT or UPDATE are not processed here.

To delete a column in a SQL table

?
ALTER TABLE nomtable DROP nomcolonne 

To add a new column

?
ALTER TABLE nomtable ADD nomcolonne type 
ALTER TABLE matable ADD colx int(4)

To change the name of a column in a SQL table

?
ALTER TABLE nom CHANGE ancien nouveau type 
ALTER TABLE matable CHANGE val qtt integer(8) 

To change the column type

?
ALTER TABLE nomtable MODIFY nomcolonne nouveautype
ALTER TABLE matable MODIFY colx decimal(3,3)

How to change the character format (charset) of the whole

tables?
ALTER TABLE nomtable CONVERT TO CHARACTER SET format COLLATE format
ALTER TABLE matable CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci

For the entire base:

ALTER DATABASE nombase DEFAULT CHARACTER SET format COLLATE format

To change the character format of a column

?
ALTER TABLE nomtable MODIFY nomcolonne type  CHARACTER SET format
ALTER TABLE matable MODIFY colx TINYTEXT  CHARACTER SET utf8

See also