I want know How mysql work when using change , modify , column inside alter table ? by copy the table , and change the differences ? or some ... thanks
Asked
Active
Viewed 4,312 times
2
-
MySQL uses pluggable engine architecture which use their own methods of dropping/adding columns and altering table and each one of them *can* use a different approach. Since there's many engines for MySQL that people use, you need to find out which engine you're interested in and check what it does in the source. Since this isn't a programming problem related question, I'm voting to close. – N.B. Apr 04 '14 at 09:31
1 Answers
10
MySQL ALTER TABLE: ALTER vs CHANGE vs MODIFY COLUMN
Whenever have to change a column in MySQL (which isn't that often), always forget the difference between ALTER COLUMN, CHANGE COLUMN, and MODIFY COLUMN
.
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;
MODIFY COLUMN
Used to do everything CHANGE COLUMN can, but without renaming the column. Example:
ALTER TABLE MyTable MODIFY COLUMN foo VARCHAR(32) NOT NULL AFTER baz;