INSERT——增
INSERT INTO <表名> (字段1,字段2......) VALUES (值1、值2......)
添加一条新纪录
INSERT INTO students (class_id, name, gender, score) VALUES (2, '大牛', 'M', 80);
一次性添加多条记录
INSERT INTO students (class_id,name,gender,score) VALUES
(1,'kaili','M',89),
(2,'choli','M',77);
UPDATE——改
UPDATE <表名> SET 字段1=值1,字段2=值2.....WHERE......;
更新id=1的记录
UPDATE students SET name='妞妞',score=99
where id=1;
更新id=5,6,7,8的记录
update students set name='huhu',score='choli'
where id in(5,6,7,8);
80分以下的学生加10分
update students set score=score+10
where score<80;
update不加where条件范围,更改的是整个表的数据,一般在应用中要使用where筛选出想要修改的记录
DELETE——删
DELETE FROM <表名> WHERE......;
删除id=1的记录
delete from students
where id=1;
删除id=4、5、6、7的记录
delete from students
where id in(4,5,6,7);
不叫where筛选,会删除整个表的数据