没有合适的资源?快使用搜索试试~ 我知道了~
计算机二级《MySQL数据库程序设计》知识点总结.doc
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2021-10-06
08:02:01
上传
评论
收藏 81KB DOC 举报
温馨提示
试读
12页
计算机二级《MySQL数据库程序设计》知识点总结.doc
资源推荐
资源详情
资源评论
- -
MySQL 知识点总结
.数据操作:检索、排序、过滤、分组、汇总、计算、联接、子查询与组合查询
.表操作:表的创立、修改、删除和重命名、表数据的插入、更新和删除
.索引〔含主、外键〕、视图
.难度编程:存储过程与存储函数、触发器与事件、PHP
.数据库管理:事务处理、用户与权限、备份与复原、数据库维护
1. 检索数据:select…from…
Select [distinct] prod_id,prod_name from products [limit 4,5];
2. 检索排序:order by…
Select * from products order by prod_id [asc|desc],prod_name [asc|desc];
3. 过滤数据:where 字句
= <> != > >= < <= between
〔1〕普通 where 字句
Select prod_id,prod_name from products where prod_name=’liyang’;
Select prod_id,prod_name from products where prod_id between 10 and
50;
Select prod_id,prod_name from products where prod_name is [not] null;
〔2〕组合 where 字句:使用 AND 和 OR 连接多个条件表达式,且 AND 次序优于 OR;
〔3〕IN 与 NOT 操作符
Select prod_id,prod_name from products where prod_id [not] in(1,2,3) |
prod_name in(’zhangsan’,’lisi’,’wangwu’);
〔4〕LIKE 操作符与通配符:“%〞与“_〞
Select prod_id,prod_name from products where prod_name like ’%liu%’;
Select prod_id,prod_name from products where prod_name like ’_u%’; 找出
u 位于名字的第二个位置的 prod_id 和 prod_name。
〔5〕正那么表达式
4. 计算字段
〔1〕拼接字段:concat(…,…)
Select concat(姓氏,名字) as from orders;
Select concat(vend_name,’(’,vend_country,’)’) from vendors;
〔2〕算术运算
Select prod_name,prod_price,prod_num,prod_price*prod_num as
prod_money from products;
4. 使用数据处理函数:文本处理函数、日期和时间处理函数、数值处理函数。
5. 汇总数据:聚集函数 SUM() AVG() COUNT() MAX() MIN()
Select avg(distinct prod_price) from products;
Select avg(prod_price) 均价,max(prod_price) 最高价 from products;
6. 分组数据:group by…创立分组、过滤分组、分组排序
Select count(prod_id),prod_id from products where prod_id>1000 group by
prod_id having count(prod_id)>2 order by prod_id;求出 prod_id 大于 1000 且
产品数量大于 2 的产品数量,并按 prod_id 排序,注意分组语句中对象要前后一致,
如下划线局部。
- - word.zl-
- -
7. 使用子查询:进展过滤 select…where…in(select…where…in(select…))、作为计
算字段使用子查询。
8. 联接:join…on…
〔1〕普通联接
Select oi.order_num,oi.prod_id,p.prod_name,p.vend_id,v.vend_name from
orderitems oi join products p on oi.prod_id=p.prod_id join vendors v on
p.vend_id=v.vend_id where vend_name=’liyang’;可同时联接多个表且可同时用
于数据过滤,这种类型的联接一般为部联接。
〔2〕自联接:一个表自己与自己联接,注意判断好各字段与前后两个表的关系。
〔3〕自然联接:根本上简历的部联接都是自然联接。
〔4〕外部联接:在关系表中没有关联的信息的行也能显示出来的联接,根据表在 join 字
句的左边还是右边可分为左联接与右联接。
〔5〕带聚集函数的联接
Select c.cust_id,count(o.order_num) num_ord from customers c join orders
o on c.cust_id=o.cust_id order by c.cust_id;找出客户对应的订单数。
9. 组合查询:连接多个〔至少两个〕查询语句,满足其中一个查询语句条件的结果都会
显示出来 union〔不重复显示〕/union all 〔可重复显示即全部显示〕
Select vend_id,prod_id,prod_price from products where prod_price<=5
Union [all]
Select vend_id,prod_id,prod_price from products where vend_id
in(1001,1002) order by prod_id;
注意每个查询必须包含一样的列、表达式或者聚集函数,列的数据类型必须兼容,排
序语句只能放在最后面,该排序语句对组合查询语句中的所有 select 语句都适用。
10. 全文本搜索:只支持引擎为 MyISAM 的表,不支持引擎为 InnoDB 的表,可对搜索结
果进展智能排序后输出,具有较高等级的行先返回。
Match(全文本搜索字段) against〔’全文本搜索容’ [with query expansion]〕其中
下划线局部为拓展语句,使用该语句,除了可以返回符合所设置的“全文本搜索容〞的
数据结果,还可返回与“全文本搜索容〞有较高相似度的数据结果。
〔1〕启用全文本搜索支持
Create table fs(id int not null primary key,c text,c1 text,fulltext(c,c1))
engine=MyISAM;
〔2〕进展全文本搜索
Select note_text from productnotes where match(note_text) against(’liyang’
with query expansion);
11. 插入数据:insert into…{values|select}…
Insert into products(prod_id,prod_name,prod_price) values(1,’豆浆’,2),(3,’鸡
蛋’,1);可同时插入多行数据。
Insert into products(prod_id,prod_name,prod_price) select
vend_id,vend_name,
vend_price from vendors where vend_id<=10;
12. 更新数据:update [ignore]…set…,一般情况下,假设更新的数据中有局部数据出
错,那么全部数据返回到原来的数据,而 ignore 的作用在于即使更新的数据中出现错
误,只对出现错误的数据返回到原来数据,而未出现错误的数据返回更新后的结果实
现更新。
- - word.zl-
- -
update products set prod_name='馒头',prod_price=1 where prod_id=1;
update customers set cust_city=concat(cust_city,’市’)| cust_city
=replace(cust_city,’市’,’city’) where cust_id>1000;
13. 删除数据:delete from…
Delete from products where prod_id between 10 an 50;
14. 表的相关操作
〔1〕创立表:对表构造进展设置 create table…
Create table products(prod_id int null auto_increment primary
key,prod_name varchar(50),prod_price int,prod_city varchar(50) default ’’)
engine=
InnoDB;每个字段名后需要设置数据类型,default 为指定默认值,只支持常量不支持
函数,且只在插入数据时起作用而在更新数据时不起作用,InnoDB 是一个可靠的事务
处理引擎,但不支持全文本搜索。
〔2〕更新表:对表构造进展修改 alter table {add|drop}…
Alter table products add prod_city varchar(50);
Alter table products drop prod_price;
〔3〕删除表:一旦删除,无法撤销 drop table…
Drop table products;
〔4〕重命名表:rename table…to…
Rename table products to new_products;
15. 索引的相关操作
〔 1 〕 创 立 索 引 : 常 用 于 数 据 的 快 速 检 索 , MySQL 中 , 常 用 索 引 在 物 理 可 分 为 :
BTREE 、 HASH 索 引 两 类 ; 在 具 体 用 途 上 可 分 为 : INDEX 、 UNIQUE 、 PRIMARY
KEY、FOREIGN KEY、FULL TEXT、SPATIAL 等。
使用 create index 语句创立索引,对已存在的表创立索引
Create [unique|fulltext|spatial] index index_name [using BTREE|HASH] on
tbl_name(index_col_name[,index_col_name…]);
Create unique index index_products on products(prod_name(2)
desc,prod_price);
使用 create table 语句创立索引,创立表的同时创立索引
Create table seller(seller_id int not null auto_increment,seller_name
char(50),seller_adress char(50),seller_contact char(50),product_type
int,sales int,primary key(seller_id,product_type),[unique|fulltext|spatial]
index index_seller(sales));
使用 alter table 语句创立索引,修改表的同时添加索引
Alter table tbl_name add {[unique|fulltext|spatial] index index_tbl_name(字
段 名 )|primary key 〔 字 段 名 〕 |foreign key 〔 字 段 名 〕 references
elsetbl_name〔一样字段名〕};
〔2〕查看索引:Show index from tbl_name [where expr];
〔3〕删除索引:drop index index_name on tbl_name 语句或 alter table 语句
Drop index index_name on tbl_name;
Alter table tbl_name drop {[unique|fulltext|spatial] index
index_tbl_name( 字 段 名 )|primary key 〔 字 段 名 〕 |foreign key 〔 字 段
名〕 references elsetbl_name 〔一样字段名 };〔下划线局部不确定〕
- - word.zl-
剩余11页未读,继续阅读
资源评论
gjmm89
- 粉丝: 14
- 资源: 19万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Matlab的运动目标跟踪系统+源代码+全部数据+文档说明+详细注释(高分课程设计)
- 基于Matlab的人脸考勤系统+源代码+全部数据+文档说明+详细注释(高分课程设计)
- 基于Matlab的异常行为检测+源代码+全部数据+文档说明+详细注释(高分课程设计)
- 基于MATLAB的条形码识别系统源码+全部数据+文档说明+详细注释+文档(高分课程设计)(带GUI界面)
- 基于C#,Winform,SQL SERVER的条形码识别操作系统+源代码+文档说明(期末大作业)
- 10_base.apk.1
- matlab-great-drawing-输出月份英文名pta
- My-Graduation-母亲节祝福python
- My-Graduation-Project华中农业大学python
- 摄像头图像采集系统.pages
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功