MySQL statement to add a field, modify field names, the type of modification, change the default value

Original Address: https://blog.csdn.net/kimgoo/article/details/54630257

Adding fields:
ALTER Table table name ADD field type constraints [Default Comments]
the ALTER TABLE Video ADD category_id int (. 11) unsigned Not null the DEFAULT '0' the COMMENT 'video classification id';


changes to field names:
ALTER Table table name rename column A to B
the ALTER tABLE Video the RENAME the cOLUMN category_id the tO CID;


modified field types:
ALTER table table modify column field name type constraints [default annotation];
the ALTER tABLE Video the mODIFY the cOLUMN category_id smallint The (. 5) unsigned Not null the dEFAULT '0' the cOMMENT 'video classification ID';


modify default value field
alter table alter column table name field names drop default; - (itself if there is a default value, then delete)
alter table alter column table default values set default field names; - ( If it does not exist in itself may be directly set)
the ALTER TABLE Video Sort the ALTER the COLUMN the DEFAULT the sET '50';

Guess you like

Origin www.cnblogs.com/phpk/p/10935759.html