计算机二级《mysql数据库程序设计》知识点总结

上传人:F****n 文档编号:100169754 上传时间:2019-09-22 格式:DOCX 页数:12 大小:38.03KB
返回 下载 相关 举报
计算机二级《mysql数据库程序设计》知识点总结_第1页
第1页 / 共12页
计算机二级《mysql数据库程序设计》知识点总结_第2页
第2页 / 共12页
计算机二级《mysql数据库程序设计》知识点总结_第3页
第3页 / 共12页
计算机二级《mysql数据库程序设计》知识点总结_第4页
第4页 / 共12页
计算机二级《mysql数据库程序设计》知识点总结_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《计算机二级《mysql数据库程序设计》知识点总结》由会员分享,可在线阅读,更多相关《计算机二级《mysql数据库程序设计》知识点总结(12页珍藏版)》请在金锄头文库上搜索。

1、MySQL知识点总结.数据操作:检索、排序、过滤、分组、汇总、计算、联接、子查询与组合查询.表操作:表的创建、修改、删除和重命名、表数据的插入、更新和删除.索引(含主、外键)、视图.难度编程:存储过程与存储函数、触发器与事件、PHP.数据库管理:事务处理、用户与权限、备份与还原、数据库维护1. 检索数据:selectfromSelect distinct prod_id,prod_name from products limit 4,5;2. 检索排序:order bySelect * from products order by prod_id asc|desc,prod_name asc|

2、desc;3. 过滤数据:where 字句= != = 1000 group by prod_id having count(prod_id)2 order by prod_id;求出prod_id大于1000且产品数量大于2的产品数量,并按prod_id排序,注意分组语句中对象要前后一致,如下划线部分。7. 使用子查询:进行过滤selectwherein(selectwherein(select)、作为计算字段使用子查询。8. 联接:joinon(1)普通联接Select oi.order_num,oi.prod_id,p.prod_name,p.vend_id,v.vend_name fr

3、om 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_i

4、d,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=5Union allSelect vend_id,prod_id,prod_pric

5、e from products where vend_id in(1001,1002) order by prod_id;注意每个查询必须包含相同的列、表达式或者聚集函数,列的数据类型必须兼容,排序语句只能放在最后面,该排序语句对组合查询语句中的所有select语句都适用。10. 全文本搜索:只支持引擎为MyISAM的表,不支持引擎为InnoDB的表,可对搜索结果进行智能排序后输出,具有较高等级的行先返回。Match(全文本搜索字段) against(全文本搜索内容 with query expansion)其中下划线部分为拓展语句,使用该语句,除了可以返回符合所设置的“全文本搜索内容”的数据

6、结果,还可返回与“全文本搜索内容”有较高相似度的数据结果。(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 intovalues|selectInsert into products(prod_id,pro

7、d_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_id1000;13. 删除数据:delete fromDelete from products where prod_id between 10 an 50;14. 表的相关操作(1)创建表:对表结构进行设置create tableCreate table product

8、s(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|dropAlter table products add prod_city varcha

9、r(50);Alter table products drop prod_price;(3)删除表:一旦删除,无法撤销 drop tableDrop table products;(4)重命名表:rename tabletoRename table products to new_products;15. 索引的相关操作(1)创建索引:常用于数据的快速检索,MySQL中,常用索引在物理可分为:BTREE、HASH索引两类;在具体用途上可分为:INDEX、UNIQUE、PRIMARY KEY、FOREIGN KEY、FULL TEXT、SPATIAL等。使用create index 语句创建索引

10、,对已存在的表创建索引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 c

11、har(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(相同字段名);

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号