DML:数据操作语言
操作对象:记录(行)
关键词:insert update delete
插入
格式:
insert into 表名 values(字段值1,字段值2,字段值3)
注意:
默认插入全部字段,
必须保存values后面的内容的类型和顺序和表结构中的一致
若字段为数字,可以省略引号
列如:
insert into user values (1,'Tom');
insert into user values ('2','Tom');
insert into user values (1,...);错误
格式2;
insert into (字段名,字段名1,字段名2.。。。)values(字段值,字段值1,字段值2.。。);
列如:insert into user(username,id)values('jack',4);
insert into user(username )values('jack',5); 错误
修改:
格式:
update 表名 set 字段名=字段值,字段名1=字段值1.。。。[where 条件]
列如:
update user set username='jerry' where username='jack';
删除:
delete from表名 [where 条件]
DQL:数据查询语言
关键词:select
格式:
select ...from 表名where 条件group by 分组字段 having条件 order by 排序手段 ase|desc
1.(补充)去重操作:比如说去除所以商品都有的那些价格 distinct
格式:
select distinct price from product;
2.可以在所查询的结果上进行运算,不影响数据库中的结果
格式 select 字段名 +num from 表明
列如: select price +10 from produts;
3.模糊匹配
格式:
字段名 like "匹配规则";
匹配内容:“龙”值为龙 “%龙”以龙结尾的 “龙%”以龙为开头的“%龙%”“值包含龙”
select *from products where pname like "%龙%";(where 的后使用)
select *from products where price between 50 and 70;(50到70之间,先小后大)
4.排序查询(asc-升序,desc-降序)
例如:select *from products order by price;