1.数据库操纵语言(Data manipulation language )DML
DML 是以任何select ,insert ,update 或 delete开头的sql 语句。
1.1 insert
示例:insert into customer value(1,'name') 或者insert into customer (id,name) values(2,'name2')
1.2seelect
示例: select * from customer ;
备注: * 表示提取所用的列的数据
1.2.1 添加where 条件
示例:select prodId ,prodName , prod_category from producats where prod_id=111;
1.2.2 and /or where 条件
示例: select cust_id ,cust_state_province ,cust_credit_limit
from customers
where cust_state_province='GS'
and cust_credit_limit >10000;
示例2:select prod_id, prod_category ,prod_weight_class WGT
from products
where prod_category = 'Hardware'
or prod_weight_class = '4';
备注;and 很or 是逻辑操作符 ,用来表示多个查询标准之间的相互影响的关系。and 关键字连接的的复合条件检索出来的记录对于所有的标准必须为真
or关键字复合条件返回的记录只需要满其中一个条件为真即可。
1.2.3 带not 的where
示例; select prod_id ,prod_category,prod_weight_class WGT
from products
where pro_weight_class !=1;
1.2.4带搜索范围的where
示例:select cust_id ,cust_gender,cust_year_of_birth
from customers
where cust_state_province = 'CT'
and cust_gender = 'M'
and cust_year_of_birth between 1936 and 1999;
1.2.5 带搜索列表的where
示例: select cust_id ,cust_state_province ,cust_credit_limit
from customers
where cust_credit_limit = 15000
and cust_state_province in ('UT' ,'CT');
1.2.6 带模式搜索的where
示例:select cust_last_name ,cust_credit_limit
from customers
where cust_last_name like 'Q%';
1.2.7 where 常用操作符
操作符 | 用途 | 示例 |
= | 测试相等 |
select *from customers where cust_state_province = 'UT' |
!= | 测试不相等 |
select *from customers where cust_state_province !='UT' |
^= | 测试不相等 |
select *from customers where cust_state_province ^= 'UT' |
<> | 测试不相等 |
select *from customers where cust_state_province <> 'UT' |
< | 小于 | select *from sales where amout_sold <100 |
> | 大于 | select *from sales where amout_sold >100 |
<= | 小于等于 | select *from sales where amout_sold <=500 |
>= | 大于等于 | select *from sales where amout_sold >=500 |
in | 等于包含任何成员 |
select * from customers where cust_state_proviince in ('UT','CA','TX') |
not in | 不等于包含的任何成员 |
select * from customers where cust_state_proviince not in ('UT','CA','TX') |
between A and B | 大于等于A且小于等于B |
select * from sales where amout_sold is between 100 and 500 |
not between A and B | 不大于等于A 不小于等于B |
select * from sales where amout_sold is not between 100 and 500 |
like '%tin%' | 包含指定文本(‘tin’) |
select *from customers where cust_last_name is like '%tin%' |