Use and differences between modify, rename, change
-
modify
-- Used to modify data constraints in fields -
rename
--Used to modify table and field names -
change
--Redefine the field, including field name and field data constraints
Let's talk about the specific usage
1. Modify the field type
alter table Table name modify Field name New data type;
2. Modify the table name
- Writing method one:
rename table Old watch name to New table name;
- Writing method two:
alter table Old watch name rename to New table name;
3. Modify the field name
alter table Table name rename column Old field name to New field name;
4. Redefine the field
alter table Table name change Old field name New field name New data type
MySQL's alter, change, modify usage
- Modify a column, the column name does not change, use modify
ALTER table order MODIFY order_fee decimal(14,4) DEFAULT NULL;
- Modify a column, change the column name, use change
ALTER TABLE apps CHANGE COLUMN at_p1 at_p2 decimal(8,4) NULL DEFAULT NULL COMMENT ‘test111' AFTER status_id;
- Add a column
ALTER TABLE apps ADD COLUMN op_date datetime(0) NULL COMMENT ‘Creation time' AFTER op_user;
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.