There will always be a time when you suddenly need to add a field in the table, add an index, or add a field, or modify it to the field. You cannot remember which command to use at a time, now, we can write some of the commands that we usually use for ease of use: 1. add the table field altertabletablenameaddnew_fieldtypenotnulldefault0; exa
There will always be a time when you suddenly need to add a field in the table, add an index, or add a field, or modify it to the field. You cannot remember which command to use at a time, now, we can write some of the commands that we usually use for ease of use: 1. add the alter table tablename add new_field type not null default '0'; exa
There will always be a time when you suddenly need to add a field, add an index, or add a field, or modify it to the field,
I can't remember which command to use at one time. Now I will write some of the commands that I usually use for ease of use:
1. Add fields in the table
Alter table tablename add new_field type not null default '0 ';
Example:
Alter table people_final_base add is_del int (11) not null default 0;
2. Modify the field name in the table
Alter table tablename change old_item new_item old_type;
Example:
Alter table people_final_base change name chinese_name varchar (50 );
3. Modify the field type
Alter table tablename change filed_name new_type;
Example:
Alter table people_final_base change create_date varchar (100 );
4. delete a field
Alter table tablename drop column column_name;
Example:
Alter table people_final_base drop column temp0;
5. Add a primary key
Alter table tablename add primary key (item );
Alter table fashion_relation_partner add primary key (pps_key );
6. Modify the primary key
Idea: First Delete the primary key and then add the primary key
Alter table tablename drop primary key;
Alter table tablename add primary key (item );
Example:
Alter table fashion_relation_partner drop primary key;
Alter table fashion_relation_partner add primary key (pps_key );
7. Set the field Default Value
Alter table fashion_warning_work alter column is_del set default 0;
Write this first, and then add it later!