3数据操作
mysql数据操作
一.添加数据
插入数据时,要注意:必填、数据类型、字符长度、传参数量
1.给指定字段添加数据
insert into student(id,name) values('3','huangshao3')
主键id和非空字段name为必填
2.给全部字段添加数据
insert into student values('7',18782940194,'黄少','男',33,'1989-09-21','数学','2023-07-19 10:54:30')
3.批量添加部分数据
insert into student(id,name) values('11','黄少11'),('12','黄少12'),('13','黄少13')
4.批量添加全部数据
insert into student values('8',18782940194,'黄少8','男',33,'1989-09-21','数学','2023-07-19 10:54:30'),('9',18782940194,'黄少9','男',39,'1989-09-20','数学','2023-07-19 10:54:30'),('10',18782940194,'黄少10','男',33,'1989-09-21','数学','2023-07-19 10:54:30')
二.更新数据
1.带条件更新单条数据
update student set course='语文' where id=5
2.带条件更新多条数据
update student set name='hs888',age=888 where id=10
3.不带条件更新所有数据
update student set course='英语'
三.删除数据
1.删除指定的单条数据
delete from student where id=1
2.删除多条数据
delete from student where name='黄少11' and name='黄少12' and name='黄少13'
3.删除全部数据
delete from student