MySQL Modify table syntax
=========================
Add column [Add column name]
=========================
①alter table name Add column list Type column parameter "Add column to last face of table"
Example: ALTER TABLE test add username char (a) not null default ';
ALTER TABLE test add birth date not null default ' 0000-00-00 ';
②alter table name Add column list type column parameter after a column "Add a new column after a column"
Example: ALTER TABLE test add gender char (1) NOT null default "after username;
③alter table name Add column list type column parameter First "Add new column to the front"
Example: ALTER TABLE TEST add PID int NOT null default 0 first;
=========================
Delete column [drop column name]
=========================
①alter table Name drop column name
Example: ALTER TABLE test drop PID;
=========================
Modify column [modife column name]
=========================
①alter table name Modify column name new type new parameter "Modify column type"
Example: ALTER TABLE test modify gender char (4) NOT null default ';
②alter table name change old column name new column name new type new parameter "Modify column name and column type"
Example: ALTER TABLE test change PID UID int. unsigned NOT NULL default 0;
=========================
Query columns
=========================
①DESC table name "Querying all Columns"
Example: DESC test;
Mysql> DESC Department;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Did | Int (11) | NO | PRI | | |
| Dname | varchar (32) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
②show columns from table name "Effect as DESC"
Mysql> Show columns from department;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Did | Int (11) | NO | PRI | | |
| Dname | varchar (32) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
③show CREATE TABLE table name "View Creation code for table"
Mysql> Show CREATE TABLE department;
CREATE TABLE ' Department ' (
' Did ' int (one) is not NULL,
' dname ' varchar (+) DEFAULT NULL,
PRIMARY KEY (' did ')
) Engine=innodb DEFAULT Charset=utf8
Linux MySQL modified data table structure syntax