MySQL开发手册(四) 数据表创建/删除

(1)创建数据表


  • 创建数据表:CREATE TABLE [IF NOT EXISTS] table_name(column_name data_type,...);
mysql> create database t1;
Query OK, 1 row affected (0.01 sec)

mysql> use t1;
Database changed
mysql> create table tb1(
    -> username varchar(20),
    -> age tinyint unsigned,
    -> salary float(8,2) unsigned
    -> );
Query OK, 0 rows affected (0.04 sec)

(2)查看数据表


  • 查看数据库中的数据表:SHOW TABLES [ FROM mysql ];
mysql> show tables;
+--------------+
| Tables_in_t1 |
+--------------+
| tb1          |
+--------------+
1 row in set (0.00 sec)

mysql> show tables from mysql;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| component                 |
| db                        |
| user                      |
+---------------------------+
33 rows in set (0.00 sec)
  • 查看数据表结构:SHOW COLUMNS FROM tb_name;
mysql> show columns from tb1;
+----------+---------------------+------+-----+---------+-------+
| Field    | Type                | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| username | varchar(20)         | YES  |     | NULL    |       |
| age      | tinyint(3) unsigned | YES  |     | NULL    |       |
| salary   | float(8,2) unsigned | YES  |     | NULL    |       |
+----------+---------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

(3)删除数据表


  • 删除数据表:drop table [if exists] table_name;
mysql> drop table tb1;
Query OK, 0 rows affected (0.05 sec)

mysql> drop table tb1;
ERROR 1051 (42S02): Unknown table 't1.tb1'
mysql> drop table if exists tb1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

笔记资源下载链接 ,支持PDF、ENEX印象笔记、HTML,方便大家整理导入

© 著作权归作者所有
这个作品真棒,我要支持一下!
主要帮助小白掌握MySQL数据库的增删改查操作,最终提供一个工具类语句手册和完善的学习笔记
0条评论
top Created with Sketch.