檢視錶的定義

20170405發表於2020-09-14

  檢視錶的定義

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(10) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  4 rows in set (0.00 sec)

  8. 刪除表

  mysql> drop table emp;

  Query OK, 0 rows affected (0.00 sec)

  9. 修改表

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(10) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  4 rows in set (0.00 sec)

  mysql> alter table emp modify ename varchar(20);

  Query OK, 0 rows affected (0.03 sec)

  Records: 0 Duplicates: 0 Warnings: 0

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  4 rows in set (0.00 sec)

  10. 刪除表欄位

  將欄位age刪除

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  | age | int(3) | YES | | | |

  +----------+---------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)

  mysql> alter table emp drop column age;

  Query OK, 0 rows affected (0.04 sec)

  Records: 0 Duplicates: 0 Warnings: 0

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  4 rows in set (0.00 sec)

  11. 欄位改名

  將age改名為age1, 同時修改欄位型別為int(4)

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  | age | int(3) | YES | | | |

  mysql> alter table emp change age age1 int(4) ;

  Query OK, 0 rows affected (0.02 sec)

  Records: 0 Duplicates: 0 Warnings: 0

  mysql> desc emp

  -> ;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  | age1 | int(4) | YES | | | |

  5 rows in set (0.00 sec)

  12. 修改欄位排列順序

  將新增的欄位birth date加在ename之後

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  | age | int(3) | YES | | | |

  5 rows in set (0.00 sec)

  mysql> alter table emp add birth date after ename;

  Query OK, 0 rows affected (0.03 sec)

  Records: 0 Duplicates: 0 Warnings: 0  

  mysql> desc emp;

  | Field | Type | Null | Key | Default | Extra |

  | ename | varchar(20) | YES | | | |

  | birth | date | YES | | | |

  | hiredate | date | YES | | | |

  | sal | decimal(10,2) | YES | | | |

  | deptno | int(2) | YES | | | |

  | age | int(3) | YES | | | |

  6 rows in set (0.00 sec)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69979119/viewspace-2719499/,如需轉載,請註明出處,否則將追究法律責任。

相關文章