1. 程式人生 > 其它 >MySQL資料庫中的表的增加,刪除,查詢操作

MySQL資料庫中的表的增加,刪除,查詢操作

技術標籤:mysql

  1. 查詢database中的表們:
    命令: show tables;
mysql> use school;
Database changed
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| emp              |
| Grade            |
| t1               |
+------------------+
3 rows in set (0.00 sec)
  1. 增加表
    命令如下:
mysql> create table t2(
    -> name char(20) not null unique,
    -> age int);
Query OK, 0 rows affected (0.00 sec)

3.刪除表
命令:drop table (if exists) table_name

mysql> drop table if exists t1,t2;
Query OK, 0 rows affected (0.00 sec)

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| emp              |
| Grade            |
+------------------+
2 rows in set (0.00 sec)

可以看到t1,t2已被刪除.其中,if exists的作用為驗證某表是否還存在,如果存在則刪除,如果不存在則自動忽略,不會報錯。