Resolved: ALTER COLUMN VS. CHANGE COLUMN
Are there any differences between the two? Or can you use it interchangeably?
2 answers ( 1 marked as helpful)
Hi Japhet!
Thanks for reaching out.
They do different things, so:
ALTER COLUMN
Used to set or remove the default value for a column. Example:
ALTER TABLE MyTable ALTER COLUMN foo SET DEFAULT 'bar';
ALTER TABLE MyTable ALTER COLUMN foo DROP DEFAULT;
CHANGE COLUMN
Used to rename a column, change its datatype, or move it within the schema. Example:
ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL FIRST;
ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32) NOT NULL AFTER baz;
Hope this helps.
Best,
Tsvetelin
Change column was used to add default and alter column to drop default in the video
you are saying alter column is for adding or dropping defaults.
ALTER TABLE customers
CHANGE COLUMN number_of_complaints number_of_complaints int DEFAULT 0;
ALTER TABLE customers
ALTER COLUMN number_of_complaints DROP DEFAULT;