找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
本帖最后由 dcs68陈昀 于 2021-11-21 20:31 编辑

如果给表中插入数据的流程:
1、在liunx交互界面先进入数据库:mysql -uroot -p123456
    mysql>看到此界面表示进入成功

2、查询一下所有数据库:show databases;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| dcs68              |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

3、进入到指定的数据库中:use +数据库名称
eg:use dcs68;进入dcs68数据库中

4、查询一下有没有可以用的表:show tables;
mysql> show tables;
+-----------------+
| Tables_in_dcs68 |
+-----------------+
| xiaoqian        |
+-----------------+
1 row in set (0.00 sec)

5、如果没有你就自己创建一个:
create table 表名称 (字段 约束;)
create table dcs(id int(3),name char(10),age int(4)); #创建一个表名称dcs
mysql> create table cici(id int(2),size int(4));

6、表结构创建好后自己查询一下表结构:
desc dcs;查询dcs表结构
mysql> desc cici;
+-------+--------+------+-----+---------+-------+
| Field | Type   | Null | Key | Default | Extra |
+-------+--------+------+-----+---------+-------+
| id    | int(2) | YES  |     | NULL    |       |
| size  | int(4) | YES  |     | NULL    |       |
+-------+--------+------+-----+---------+-------+
2 rows in set (0.00 sec)

7、然后插入数据删除查询操作
insert into 插入数据
mysql> insert into xixi(id,name,age,scroe)values(1,'zhangsan',24,78);
Query OK, 1 row affected, 1 warning (0.00 sec)

select * from 表; 查询
mysql> select * from xixi;
+------+------+------+-------+
| id   | name | age  | scroe |
+------+------+------+-------+
|    1 | zhan |   24 |    78 |
+------+------+------+-------+
1 row in set (0.00 sec)

delete from 表; 删除
mysql> delete from cici;
Query OK, 1 row affected (0.00 sec)

1、表数据(重点)
表数据操作语言:DML
增删改查:insert into , delete , update , select
1)表中增加数据
结构:id ,name ,age ,scroe
insert into stu(id,name,age,scroe) values(1,'zhang',20,89); #增加一行数据
insert into stu values(2,'wang',19,100),(3,'lisi',20,99); #增加多行数据
insert into xiaoqian(name,age)values('zng',22),('ang',21),('wang',31);#自增长和主键同时插入多行数据
2)查询数据
select * from 表名称 查询所有的数据
3)删除表的数据
where条件表达式
delete from stu where id=4; #删除表中id=4的这一行的数据
mysql> delete from xixi where id=4;
Query OK, 1 row affected (0.01 sec)

mysql> select * from xixi;
+----+------+------+-------+
| id | name | age  | scroe |
+----+------+------+-------+
|  1 | zhan |   24 |    78 |
|  2 | zhao |   22 |  NULL |
|  3 | zhao |   22 |  NULL |
+----+------+------+-------+
3 rows in set (0.00 sec)
delete from stu;删除整个表中的所有数据
备注:delete只能删除表数据,不能删除表结构,如需要删除表结构需要用drop table。
4)删除整个表的数据
truncate +表名字
备注:truncate只能删除表数据,不能删除表结构,如需要删除表结构需要用drop table。
5)修改表数据
update 表名称 set 修改的值 where 条件指定;
update stu set name='zhang' where id=1; #把id=1这一行的姓名改为zhang
update xiaoqian set name='xiaoqian';#把所有的姓名都改为xiaoqian

2、查询(重点)
查询所有:select * from 表名称;
select * from stu; 查询stu表中的所有内容
通过条件查询某个条件的值:select * from 表名称 where 条件;
查询姓名时xiaoqian的所有内容: select * from stu where name='xiaoqian';
通过条件查询满足几个条件的内容:select * from 表名称 where 条件 and 条件;
查询满足姓名是qian年纪是20的数据:select * from stu where name='qian' and age=20;

大于>           select * from stu where scroe>60; 大于60分所有信息
小于<           select * from stu where scroe<60;小于60分所有信息
等于=           select * from stu where scroe=60;等于60分所有信息
大于等于>=     select * from stu where scroe>=60;大于等于60分所有信息
小于等于<=     select * from stu where scroe<=60;小于等于60分所有信息
不等于!=       select * from stu where scroe !=60;不包含60分的所有信息
in指定具体的值  select * from stu where scroe in(60,88,99);指定的值有就显示,没有就不显示
查询张三的信息,告诉张三的年纪的多少?
select * from stu where name='张三';(所有信息都出来了)
select age from stu where name='张三';

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册