MySQL operation existing table (alter table)

Time:2021-6-16

explain:

  • The content in < > is self defined
  • The contents in [] can be omitted
  • Field contains the field name and data type_ Name only refers to the field name
  • table_ Name refers to the name of the table
  • Position refers to the position of the field, and the values can be: first, after < field > field
catalogue
  • Modify table name
  • Add field
  • Modify field
  • Delete field
  • Modify field defaults
  • Delete field defaults
  • Modify storage engine

Modify table name

--Modify the name of the data table.
-- old_ table_ Name is the name before the modification
-- new_ table_ Name is the modified name
ALTER TABLE <old_table_name> RENAME [TO] <new_table_name>;

Add field

--Adding fields to a data table
ALTER TABLE <table_name> ADD [COLUMN] <field> [position];

If you need to add multiple fields, use,connect
eg.
ALTER TABLE <table_name> ADD [COLUMN] <field> [position], ADD [COLUMN] <field> [position], …;

Modify field

  • Modify field name
ALTER TABLE <table_name> CHANGE [COLUMN] <field_name> <field> [position];
  • Modify field type
ALTER TABLE <table_name> MODIFY <field_name> <new_type> [position];
--Or
ALTER TABLE <table_name> CHANGE [COLUMN] <field_name> <field_name> <new_type> [position];
  • Modify the location of the field
ALTER TABLE <table_name> MODIFY <field> [position];
--Or
ALTER TABLE <table_name> CHANGE [COLUMN] <field_name> <field> [position];

Delete field

ALTER TABLE <table_name> DROP <field_name>;

Modify field defaults

ALTER TABLE <table_name> ALTER <field_name> SET DEFAULT <value>;

Delete field defaults

ALTER TABLE <table_name> ALTER <field_name> DROP DEFAULT;

Modify storage engine

ALTER TABLE <table_name> ENGINE = <engine_name>;

Recommended Today

The selector returned by ngrx store createselector performs one-step debugging of fetching logic

Test source code: import { Component } from ‘@angular/core’; import { createSelector } from ‘@ngrx/store’; export interface State { counter1: number; counter2: number; } export const selectCounter1 = (state: State) => state.counter1; export const selectCounter2 = (state: State) => state.counter2; export const selectTotal = createSelector( selectCounter1, selectCounter2, (counter1, counter2) => counter1 + counter2 ); // […]