1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| 库.表 表
root@localhost:student > desc stu300; +-----------+---------------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+-------------------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | name | varchar(20) | NO | | NULL | | | age | tinyint(4) unsigned | NO | | NULL | | | gender | enum('m','f') | NO | | m | | | phone | char(11) | NO | PRI | NULL | | | come_time | datetime | NO | | CURRENT_TIMESTAMP | | +-----------+---------------------+------+-----+-------------------+----------------+
1、#不规范 往stu300表里面增加数据 root@localhost:student > insert into stu300 values(5,'ccc',23,'f',12312312388,now());
2、#规范写法 往stu300表里面增加数据 root@localhost:student > insert into stu300(name,age,phone,class) values('ddd',18,12312312399);
3、#插入多条数据 inster stu2 表名(字段1,字段2,字段3) values(1,2,3),(1,2,4),(1,3,5);
root@localhost:student > insert into stu300(name,age,phone) values('eee',27,2312312389),('fff',27,2313312389),('bbb',27,3312312389);
4、#into可以省略 inster 表名(字段1,字段2,字段3) values(1,2,3);
root@localhost:student > insert stu300(name,age,phone) values('ggg',21,2333312389);
手机号位数不对,都是前端打印的,数据库做不到手机号位数不对报错 jwt匹配库
root@localhost:student > select * from stu300; +----+------+-----+--------+-------------+---------------------+ | id | name | age | gender | phone | come_time | +----+------+-----+--------+-------------+---------------------+ | 1 | aaa | 13 | m | 12345465666 | 2024-08-12 21:20:05 | | 3 | cc | 12 | m | 23456781234 | 2024-08-12 21:22:25 | | 5 | ccc | 23 | f | 12312312388 | 2024-08-13 14:08:27 | | 6 | ddd | 18 | m | 12312312399 | 2024-08-13 14:10:08 | | 7 | eee | 27 | m | 2312312389 | 2024-08-13 14:12:43 | | 8 | fff | 27 | m | 2313312389 | 2024-08-13 14:12:43 | | 9 | bbb | 27 | m | 3312312389 | 2024-08-13 14:12:43 | | 10 | ggg | 21 | m | 2333312389 | 2024-08-13 14:15:08 | +----+------+-----+--------+-------------+---------------------+
dellete删除必须接条件 打完delete 就要打where delete from 表 where id=5 1、#不规范的写法,谨慎使用,会删除表里面的全部数据 delete from stu300;
2、#规范写法 PRIMARY KEY (`Host`,`User`) 联合主键,就要2个组件一起删除 root@localhost:student > delete from stu300 where id=8;
3、#多条件 and root@localhost:student > delete from stu300 where id=10 and name='ggg';
4、#为了养成一个好习惯delete + where,若要清除全部数据,表名不清除 root@localhost:student >delete form stu1 where 1=1;
1、#不规范写法 如果不加where 所有的name都叫一样的名字 update stu300 set name='lisi'
2、#将id为1的用户改名为张三 root@localhost:student > update stu300 set name='zhangsan' where id=1;
3、#将id是7,和9 的用户名字改为李四 root@localhost:student > update stu300 set name='lisi' where id=7 or id=9;
4、#要全部改,后面接一个成立的条件 update stu300 set name='zhang3' where 1=1;
select * from stu300;
select * from stu300 where status='1';
|