ALTER TABLE
The optional (when used before the table name) clause causes the error to be suppressed if the table does not exists.
The optional IF EXISTS
(when used before the column name) clause causes the error to be suppressed if the column does not exists.
The optional IF NOT EXISTS
clause causes the error to be suppressed if the column already exists.
ALTER TABLE users RENAME TO people;
Rename table users
to people
if table users
exists:
Add column zip
to the table:
Add column zip
to the users
table if table users
exists and column zip
not already exists:
ALTER TABLE IF EXISTS users ADD COLUMN IF NOT EXISTS zip varchar;
ALTER TABLE users DROP COLUMN zip;
Drop column zip
from the users
table if table and column zip
exists:
Rename column id
to user_id
in the users
table:
Rename column id
to user_id
in the users
table if table users
and column id
exists: