turn:
Mysql using SQL to add, delete, modify (including field length / comment / field names) summary
Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/m0_37721946/article/details/82414501
-
Add a field #
-
alter table table Field Name Type Length add COLUMN the DEFAULT NULL the COMMENT 'footnotes';
-
-
#E.g:
-
Table device_log_run_operation the Add the COLUMN parser_status ALTER VARCHAR ( . 4) the DEFAULT NULL the COMMENT 'document parse state, 0: successfully resolved; 1: parsing failure;';
-
-
-
-
# Batch add fields, a method
-
# Transaction begins
-
begin;
-
alter table device_log_run_operation add COLUMN title VARCHAR( 500) DEFAULT NULL COMMENT '日志标题';
-
alter table device_log_run_operation add COLUMN remote_addr VARCHAR( 255) NOT NULL COMMENT '操作ip地址';
-
commit;
-
# Batch add fields, commit the transaction, the transaction ends
-
-
-
# New batch field, Method II
-
alter table table add (field name type (length), field name second type (length), field name 3 type (length));
-
-
#E.g:
-
alter table device_log_run_operation
-
add (
-
int Status ( . 11) the DEFAULT NULL the COMMENT 'Status: 0 - Success; 1- failure',
-
VARCHAR remote_addrss ( 255) the NOT NULL the COMMENT 'IP address of the operation',
-
datetime insert_times the DEFAULT NULL the COMMENT 'Creation Time'
-
);
-
-
-
# Add comments to the table
-
ALTER TABLE table name the COMMENT 'table footnotes';
-
TABLE device_files_info the COMMENT the ALTER 'device operation file';
-
-
-
A length field # modify / add annotations
-
alter table modify column table the COMMENT field Name Type Length 'field footnotes';
-
-
#E.g:
-
alter table device_log_run_operation modify column title varchar( 500) COMMENT '标题';
-
-
-
# Batch modify the field name
-
alter table table name
-
Modify field name change before and after modification field name int ( 11) not null,
-
Modify field name change before and after modification field name int ( 11) not null
-
-
#E.g:
-
alter table device_log_run_operation
-
remote_addrss opeartor_ip VARCHAR Change ( 255) the DEFAULT NULL the COMMENT 'IP address of the operation',
-
datetime insert_time create_time Change the DEFAULT NULL the COMMENT 'Creation Time'
-
-
-
-
# Delete a field
-
alter table DROP COLUMN table name field name;
-
alter table device_log_run_operation DROP COLUMN status ;
-
-
-