使用的工具是wamp的Mysql. P29 select prod_name from products;  #在表products中选列prod_name,顺寻不是纯粹的随机,但是没有说明排列顺序,所以不能说明检索出来的该顺序有意义. P30 select prod_name from products order vy prod_name;  #order by 表示 prod_name按字母顺序排序. P30 select prod_id,prod_price,prod_name from…
第七章:数据过滤 P43 select prod_id,prod_price,prod_name from products where vend_id =1003 and prod_price <=10;  #检索vend_id=1003 并且prod_price<=10 # select prod_name,prod_price from products where vend_id=1002 or vend_id =1003; #检索的条件只要满足vend_id=1002 ,vend_i…
第六章<过滤数据> P35 1. select prod_name,prod_price from products where prod_price=2.5; 2.select prod_name,prod_price from products where prod_price='2.5'; #两个语句得到的结果一样,因为指定的是数值. P36 select prod_name,prod_price from products where prod_name='fuses'; #当指定的是…
第18章 全文本搜索 P121  #创建一个新表,对表的列进行定义,定义之后,MySQL自动维护该索引# create table productnotes ( note_id  int   NOT NULL  AUTO_INCREMENT, prod_id char(10)  NOT NULL  , note_date datetime  NOT NULL , note_text text NULL, PRIMARY KEY(note_id), FULLTEXT (note_text ) )E…
第22章:使用视图,视图是虚拟的表,以表形式呈现的是你查询的结果.并不是说在数据库里面真的存在这个表,但是是真的存在这些数据. select cust_name,cust_contact from customers ,orders,orderitems where customers.cust_id=orders.cust_id and orderitems.orderitems.order_num=orders.order_num and prod_id='tnt2'; P158 creat…
第20章:更新和删除数据 P140 update customers set_emails='elmer@fudd.com' where cust_id=10005; 更新多个列,用逗号隔开.注意被指定的词有引号,null不用引号. #为什么cust_name不能是空值# ##删除一个列,把一个列的值改为空值## P141删除数据 select from customers where cust_id=10006; #删除cust_id=10006的的行所有信息#…
第19章 插入数据 P132 insert into customers VALUES(NULL,'Pep E.Lapew','100 Main Street',,Los Angeles','CA','90046','USA',NULL,NULL); #customers表中刚好有9个维度(一定要对应上),9个值会对应这9个维度,维度的次序由表定义# insert into customers (cust_name,cust_address,cust_city,cust_state,cust_z…
第17章:组合查询 P114 select vend_id ,prod_id,prod_price from products where prod_price <=5 ; select vend_id ,prod_id,prod_price from products where vend_id in (1001,1002); P115 组合上面的两个语句. select vend_id ,prod_id,prod_price from products where prod_price <…
第16章:创建高级联结. P106 select concat(RTrim(vend_name),'(',RTrim(vend_country),')') as vend_title from vendors order by vend_name;   #concat()函数合并两列,并重新命名合并的列为vend_name.# select cust_name,cust_contact from customers as c,orders as o,orderitems as oi where…
第15章:联结表 P98 外键:外键为某个表的一列A,同时这一列包含另一个表的主键值B(B属于A,等于或者小于的关系) P99 select vend_name,prod_name,prod_price from vendors,products where vendors.vend_id =products.vend_id order by vend_name,prod_name; # 选择的vend_name,prod_name只是在products表格中出现,所以无须指明是哪个表,这个的语…
第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2';   #检索条件为prod_id=tnt2的order_num# select cust_id from orders where order_num in (20005,20007);    #检索满足条件 order_num在范围(20005,20007)的cust_id# select cust_id fro…
第13章:分组过滤. P83 select count(*) as num_prods from products where vend_id=1003; #返回vend_id=1003的产品数目总值# P84 select count(*) as num_prods from products group by vend_id; #返回各个vend_id所提供的产品数量,不需要指定计算每个组,因为用了group by ,系统会自动完成# 注意:group by必须在where 之后,order…
第12章:汇总数据 P76 avg()函数求平均值 select avg(prod_price) as avg_price from products; #计算prod_price的平均值,并且命名为avg_price# select avg(prod_price) as avg_price from products where vend_id=1003; #计算priod_id=1003的prod_price的平均值,并且命名为avg_price# select count(*) as nu…
第11章:使用数据处理函数. P69 文本处理函数,upper()函数把文本变成大写字体. select vend_name,upper(vend_name) as vend_name_upcase from vendors order by vend_name; #upper()把vend_name列的文本变成了大写,并且重新命名为vend_name_upcase # 其他的常用的函数: length()返回串的长度 lower() 将文本变成小写字体. 其他的,left()返回串左边的字符,…
第10章,计算字段. P64 select concat (vend_name,'(',vend_country,')') from vendors order by vend_name; # 拼接,vend_name(vend_country) # P65 使用别名 select concat(RTrim(vend_name),'(',RTrim(vend_country),'),') as vend_titile from vendors order by vend_name;  #拼接ve…
第九章,用正则表达式进行搜索. P52 select prod_name from products where prod_name regexp '1000' order by prod_name; #regexp后面所跟着的文字为正则表达式,regexp匹配任何的字符# select prod_name from products where prod_name regexp '.000' order by prod_name; #点(.)表示匹配任何的字符# LIKE和REGEXP的区别,…
P27: select prod_name from products; # select 列 from 表 # 从表products 中检索 名为 prod_name 的列 P28 多个语句一起必须要加上分号(:) select prod_name from products;select vend_id from products; #这是两条语句,两个都加上分号,就会一起运行# P22 select prod_id,prod_name,prod_price from products; #…
P16: use crashcourse; #选择数据库#使用crashcouse这个数据库,因为我没有crashcourse这个数据库,所以用我的hh数据库代替. P17: show databases; #查看可以使用的数据库# show tables; #查看刚刚使用的数据库hh里面的表有哪些# P18: show columns from customers; #查看表customers中有多少列#以及列名:数据类型,等信息... decribe customers; #是show co…
  上图为数据库操作分类:     下面的操作參考(mysql必知必会) 创建数据库 运行脚本建表: mysql> create database mytest; Query OK, 1 row affected (0.07 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | mytest | | per…
前言 MySQL已经成为世界上最受欢迎的数据库管理系统之一.无论是用在小型开发项目上,还是用来构建那些声名显赫的网站,MySQL都证明了自己是个稳定.可靠.快速.可信的系统,足以胜任任何数据存储业务的需要. 本书基于我的一本畅销书 Sams Teach Yourself SQL in 10 Minutes (中文版<SQL必知必会>,人民邮电出版社),那本书堪称全世界用的最多的一本SQL教程,重点讲解读者必须知道的东西,条理清晰,系统而扼要.但是,即使是那样一本广为使用的成功的书,也还是存在着…
<MySQL必知必会>通配符 ( like , % , _ ,) 关键字 LIke WHERE 搜索子句中使用通配符,必须使用 LIKE 操作符. % 百分号通配符 % 表示任意字符出现任意次数.(这里的任意当然包括 0 .1.无数) select prod_id,prod_name from products where prod_name like 'jet%'; 注意: 通配符搜索是可以区分大小写的. 使用关键字 Binary 即可 select prod_id,prod_name fr…
 例如以下为mysql必知必会第九章開始: 正則表達式用于匹配特殊的字符集合.mysql通过where子句对正則表達式提供初步的支持. keywordregexp用来表示后面跟的东西作为正則表達式处理. (.)是正則表達式的一个符号,表示匹配随意一个字符: mysql> select prod_name -> from products -> where prod_name regexp '.000' -> order by prod_name; +--------------…
简介 此笔记只包含<MySQL必知必会>中部分章节的整理笔记.这部分章节主要是一些在<SQL必知必会>中并未讲解的独属于 MySQL 数据库的一些特性,如正则表达式.全文本搜索.MySQL 中的数据类型等. 此笔记可以看作是对<MySQL必知必会>中包含而<SQL必知必会>中不包含的内容的一个补充. 目录 此笔记的所有内容都在下面的链接中: 文档:<MySQL必知必会>…
<MySQL必知必会>(点击查看详情) 1.写在前面的话 这本书是一本MySQL的经典入门书籍,小小的一本,也受到众多网友推荐.之前自己学习的时候是啃的清华大学出版社的计算机系列教材<数据库系统概论>,基础也算是半罐水,糊里糊涂,知识点欠缺梳理.于是,也算是借此机会,从这本书对数据库和SQL部分的知识点进行梳理,记录一下基础的关键的东西,也便于以后翻阅查询,好了,就不叨叨了. 2.MySQL基本操作 命令输入在 mysql> 之后: 命令用:或 \g 结束,仅按Enter不执…
春节放假没事,找了本电子书mysql必知必会敲了下.用的工具是有道笔记的markdown文档类型. 下面是根据大纲已经敲完的章节,可复制到有道笔记的查看,更美观. # 第一章 了解SQL## 什么是SQL#### SQL(Structured Query Language)机构化查询语言,是一种专门与数据库通信的语言.***### 什么是数据库?  #### 数据库是一个以某种有组织的方式存储的数据集合. 数据库(database):保存有组织数据的容器(通常是一个文件或一组文件)  *** #…
前言 最近在写项目的时候发现自己的SQL基本功有些薄弱,遂上知乎查询MYSQL关键字,期望得到某些高赞答案的指点,于是乎发现了 https://www.zhihu.com/question/34840297/answer/272185020 这位老兄的建议的书单,根据他的建议首先拜读了<MYSQL必知必会>这本书,整体讲的很基础,页数也不多一共 253 页,适合基础比较薄弱的同学进行食用.然后循序渐进,阅读更深层次的书籍进行自我提升.这里记载了自己在阅读的过程中记录的一些关键内容,分享给大家.…
参考书籍: BookName:<SQL必知必会(第4版)> BookName:<Mysql必知必会(第4版)> Author: Ben Forta 说明:本书学习笔记 1.了解SQL 1.1 数据库基础 1.1.1 数据库 数据库是一个以某种有组织的方式存储的数据集合,即保存有组织的数据的容器(通常是一个文件或一组文件). 数据库软件应称为数据库管理系统(DBMS). 1.1.2 表 表是一种结构化的文件,可用来存储某种特定类型的数据. 模式,关于数据库和表的布局及特性的信息. 1…
MySQL备忘 目录 目录 使用MySQL 检索数据 排序检索数据 过滤数据 数据过滤 用通配符进行过滤 用正则表达式进行搜索 创建计算字段 使用数据处理函数 数值处理函数 汇总数据 分组数据 使用子查询 作为计算字段使用子查询 联结表 创建高级联结 组合查询 全文本搜索 插入数据 更新和删除数据 使用MySQL mysql -u<usr> -p -h<host> -P <port> 分别指明用户名,主机名,端口号 show columns from <table…
MySQL必知必会 简介 <MySQL必知必会>的学习笔记和总结. 书籍链接 了解SQL 数据库基础 什么是数据库 数据库(database):保存有组织的数据的容器(通常是一个文 件或一组文件). 确切地说,数据库软件应称为DBMS(数据库管理系统).数据库是通过DBMS创建和操纵的容器.数据库可以是保存在硬设备上的文件,但也可以不是. 表 表(table):某种特定类型数据的结构化清单. 表名的唯一性取决于多个因素,如数据库名和表名等的结合.这表示,虽然在相同数据库中不能两次使用相同的表名…
这是 <MySQL 必知必会> 的读书总结.也是自己整理的常用操作的参考手册. 使用 MySQL 连接到 MySQL shell>mysql -u root -p Enter password:****** 显示数据库 mysql>SHOW DATABASES; 选择数据库 mysql>USE mytest; 显示数据库中的表 mysql>SHOW TABLES; 显示表列 mysql>SHOW COLUMNS FROM tmall_user; mysql>…