查看表的结构
desc 表名;
mysql> use study;
Database changed
mysql> create table Class(class_id int ,class_name varchar(128),class_teachar varchar(64)) ;
Query OK, 0 rows affected (0.06 sec)
mysql> show tables;
+-----------------+
| Tables_in_study |
+-----------------+
| class |
+-----------------+
1 row in set (0.00 sec)
mysql> desc class;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| class_id | int | YES | | NULL | |
| class_name | varchar(128) | YES | | NULL | |
| class_teachar | varchar(64) | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
3 rows in set (0.01 sec)
存放表里面数据
mysql> insert into Class values(101,'一年级一班','张三');
Query OK, 1 row affected (0.02 sec)
mysql> insert into Class values(102,'一年级二班','李四');
Query OK, 1 row affected (0.01 sec)
查看表数据
mysql>
mysql> select class_id from class;
+----------+
| class_id |
+----------+
| 101 |
| 102 |
+----------+
2 rows in set (0.00 sec)
mysql> select * from class;
+----------+------------+---------------+
| class_id | class_name | class_teachar |
+----------+------------+---------------+
| 101 | 一年级一班 | 张三 |
| 102 | 一年级二班 | 李四 |
+----------+------------+---------------+
2 rows in set (0.00 sec)
mysql>
mysql> select class_id,class_name from class;
+----------+------------+
| class_id | class_name |
+----------+------------+
| 101 | 一年级一班 |
| 102 | 一年级二班 |
+----------+------------+
2 rows in set (0.00 sec)
mysql>
mysql> select class_teachar from class where class_name = '一年级一班';
+---------------+
| class_teachar |
+---------------+
| 张三 |
+---------------+
1 row in set (0.00 sec)
mysql>
mysql> select class_name from class where class_teachar = '李四';
+------------+
| class_name |
+------------+
| 一年级二班 |
+------------+
1 row in set (0.00 sec)
mysql>
mysql> select class_name from class where class_id = 101;
+------------+
| class_name |
+------------+
| 一年级一班 |
+------------+
1 row in set (0.00 sec)
mysql>
mysql> select class_teachar from class where class_id = 102;
+---------------+
| class_teachar |
+---------------+
| 李四 |
+---------------+
1 row in set (0.00 sec)
mysql>
mysql> select * from class where class_teachar = '李四';
+----------+------------+---------------+
| class_id | class_name | class_teachar |
+----------+------------+---------------+
| 102 | 一年级二班 | 李四 |
+----------+------------+---------------+
1 row in set (0.00 sec)