MySql复习 #Day 1

1.增删改查基本语句详解

*增删改查都是针对表来说的

1.1 insert增数据语句

思考问题:

三要素:往那张表增加数据?往哪一行添加数据?添加数据的值是多少?

1.1.1

insert into tbname 
[columns] 
values 
(...),
(...),
(...);

所选择的列与(...)中的值严格一一对应

1.1.2自增长型不插入也会自动增长如id,但是不能因为自增长就不给其赋值,因为一一对应,所以在赋值时会不匹配

e.g:

#向Whitepaper表中添加数据
insert into whitepaper
values
(8,4,'unkown',78910);

insert into whitepaper
(cat_id,name,brand_price)
values
(1,'peking',6635);

1.2 update更新数据

四要素:修改哪一张表?修改哪一列?哪一行?将该值改为多少?

1.2.1

update tbname
set
column1 = '',
column2 = '',
where exp;

where exp 用来限制所改的行,只要表达式exp为真,则在该行发挥作用

1.2.2  exp表达式的条件可以使用and,or和not进行多重条件判定

1.2.3 where 1 恒为真

e.g:


update whitepaper
set
cat_id = 3,
brand_price = 7756
where id =9;

update whitepaper
set 
brand_price = 10000
where id>3 and cat_id =4;

1.3 delete删除数据

1.3.1 问:存不存在这个可能,即只删除某列某行中的某一个值?

         答:不存在,删除只能删除一整行

1.3.2  两要素:要删哪张表上的数据?要删去哪一行?

1.3.3 

delete tbname
where exp;

where exp用来限制删除的行

例如:

#删除lass表中,薪水(salary)高于8800的人的所有信息
mysql->delete class
     ->where salary > 8800;

1.4  select查询语句详解

1.4.1 三要素:要查询哪张表的数据?查询那一列?哪一行?

1.4.2 

select (columns1,column2,) or (*) from tbname
where exp;

同上,where exp用来限制查询的行

猜你喜欢

转载自blog.csdn.net/KageYamaa/article/details/81239568
今日推荐