Mysql using SQL to add, delete, modify (including field length / comment / field names) summary

 

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
  1. Add a field #
  2. alter table table Field Name Type Length add COLUMN the DEFAULT NULL the COMMENT 'footnotes';
  3.  
  4. #E.g:
  5. 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;';
  6.  
  7.  
  8.  
  9. # Batch add fields, a method
  10. # Transaction begins
  11. begin;
  12. alter table device_log_run_operation add COLUMN title VARCHAR( 500) DEFAULT NULL COMMENT '日志标题';
  13. alter table device_log_run_operation add COLUMN remote_addr VARCHAR( 255) NOT NULL COMMENT '操作ip地址';
  14. commit;
  15. # Batch add fields, commit the transaction, the transaction ends
  16.  
  17.  
  18. # New batch field, Method II
  19. alter table table add (field name type (length), field name second type (length), field name 3 type (length));
  20.  
  21. #E.g:
  22. alter table device_log_run_operation
  23. add (
  24. int Status ( . 11) the DEFAULT NULL the COMMENT 'Status: 0 - Success; 1- failure',
  25. VARCHAR remote_addrss ( 255) the NOT NULL the COMMENT 'IP address of the operation',
  26. datetime insert_times the DEFAULT NULL the COMMENT 'Creation Time'
  27. );
  28.  
  29.  
  30. # Add comments to the table
  31. ALTER TABLE table name the COMMENT 'table footnotes';
  32. TABLE device_files_info the COMMENT the ALTER 'device operation file';
  33.  
  34.  
  35. A length field # modify / add annotations
  36. alter table modify column table the COMMENT field Name Type Length 'field footnotes';
  37.  
  38. #E.g:
  39. alter table device_log_run_operation modify column title varchar( 500) COMMENT '标题';
  40.  
  41.  
  42. # Batch modify the field name
  43. alter table table name
  44. Modify field name change before and after modification field name int ( 11) not null,
  45. Modify field name change before and after modification field name int ( 11) not null
  46.  
  47. #E.g:
  48. alter table device_log_run_operation
  49. remote_addrss opeartor_ip VARCHAR Change ( 255) the DEFAULT NULL the COMMENT 'IP address of the operation',
  50. datetime insert_time create_time Change the DEFAULT NULL the COMMENT 'Creation Time'
  51.  
  52.  
  53.  
  54. # Delete a field
  55. alter table DROP COLUMN table name field name;
  56. alter table device_log_run_operation DROP COLUMN status ;
  57.  
  58.  
  59.  

 

Guess you like

Origin www.cnblogs.com/libin6505/p/10980019.html