查看表的结构
sql
desc 表名;
bash
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)
存放表里面数据
bash
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)
查看表数据
bash
mysql> #按照班级id查询
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> #查询 带条件的表数据 在那个班级id为101
mysql> select class_name from class where class_id = 101;
+------------+
| class_name |
+------------+
| 一年级一班 |
+------------+
1 row in set (0.00 sec)
mysql> #查询 带条件的表数据 在那个班级为102的老师是
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)