Mysql 2 —— 最基本的增删改查

添加值的操作

1.往哪张表添加行?2.给哪几列添加值?3.分别是什么值?

insert into class
(id,sname,gender,company,salary,fanbu)
values
(1,'張三','男','百度',8888.67,234);

mysql> insert into class
-> (sname,gender,salary)
-> values
-> ('刀鋒','男',8765.43);

id在上例中虽然没有插入,但是id是自增型,因此值为2,
回头再来看,插入所有列的情况,如果插入所有列,则可以不声明待插入的列。
即如果不声明插入的列,则理解为一次插入所有列

insert into class
values
(3,'李四','男','新浪',8788.67,204);

提醒不要犯如下错误,
有同学认为id是自增型的,插入时不必为其赋值
insert into class
values
('李四','男','新浪',8788.67,204);///错

输入多个数据
insert into class
(sname,gender,company,salary)
values
('刘备','男','皇室成员',15.28),
('孙策','男','江东成员',56.32),
('曹操','男','宦官后代',86.52);

改表格中数据
update 改的要素
改哪几张表: update
改哪几行: gender, company
改成什么值: '女','千'

mysql> update class
-> set fanbu = 123
-> where id=6;

mysql> update class set gender ='',fanbu='212' where sname = '孙策';
如果有两个'孙策',就改两个

改性别为男并且工资c>8000的用户
update class set fanbu=159 where gender='男' and salary>8000;

删除就是指删除整行,不存在删除一行中的某几列
1.删哪张表的数据:class
2.删哪几行:where expression

delete from class where salary>8800;

查询三要素
1.查那张表 class
2.查那些列

select sname,company,salary from class where id=6;

展示数据:
mysql> select * from newstu;

 

posted @ 2020-10-24 11:25  我等着你  阅读(100)  评论(0)    收藏  举报