MySQL資料庫中的表的增加,刪除,查詢操作
阿新 • • 發佈:2021-01-15
技術標籤:mysql
- 查詢database中的表們:
命令: show tables;
mysql> use school;
Database changed
mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| emp |
| Grade |
| t1 |
+------------------+
3 rows in set (0.00 sec)
- 增加表
命令如下:
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的作用為驗證某表是否還存在,如果存在則刪除,如果不存在則自動忽略,不會報錯。