记文档还是相当重要的! 索引 假名的三个用途 自交(Self Joins) 自然交(Natural Joins) Outer Joins Using Table Aliases Using aliases for column names and calculated fields To shorten the SQL syntax To enable multiple uses of the same table within a single SELECT statement 自交 像下面这…
索引 理解相关表. foreign key JOIN 与保持参照完整性 关于JOIN 的一些建议,子查询 VS. 联表查询 我发现MySQL 的官方文档里是有教程的. SQL Tutorial - W3Schools The SQL Tutorial for Data Analysis | SQL Tutorial - Mode Analytics Understanding Relational Tables The key here is that having multiple occur…
以前写过类似的东西,用来自动生成数据. 你可以将 Stored Procedure 理解为可以重复使用的批处理文件. Stored Procedure 非常有用,我们应该尽可能地去使用它. 那么,应用 Stored Procedure 有什么好处呢? 封装过程,简化复杂的操作 代码重用.共用,所有人都用同一个存储过程,减少出错的可能 简化变更管理,如果业务逻辑发生改变,修改存储过程就可以了,上层软件甚至不需要知道发生了什么改变. 提高性能,存储过程比单条执行要快 MySQL 语言让存储过程更加强…
之前 manipulate 表里的数据,现在则是 manipulate 表本身. INDEX 创建多列构成的主键 自动增长的规定 查看上一次插入的自增 id 尽量用默认值替代 NULL 外键不可以跨引擎 添加字段与删除字段 & 定义外键 复杂表结构的修改 删除表与修改表名 非常工整的 . .模范脚本: CREATE TABLE customers ( cust_id int NOT NULL AUTO_INCREMENT, cust_name ) NOT NULL , cust_address…
INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Deleting Data Updating Data UPDATE customers SET cust_name = 'The Fudds', cust_email = 'elmer@fudd.com' ; To delete a column's value, you can set it to NU…
INDEX BAD EXAMPLE Improving Overall Performance Inserting Multiple Rows INSTEAD OF Inserting a Single Row Inserting Retrieved Data BAD EXAMPLE INSERT INTO Customers VALUES(NULL, 'Pep E. LaPew', '100 Main Street', 'Los Angeles', 'CA', ', 'USA', NULL,…
索引 理解 GROUP BY 过滤数据 vs. 过滤分组 GROUP BY 与 ORDER BY 之不成文的规定 子查询 vs. 联表查询 相关子查询和不相关子查询. 增量构造复杂查询 Always More Than One Solution As explained earlier in this chapter, although the sample code shown here works, it is often not the most efficient way to perf…
索引 AND. OR 运算顺序 IN Operator VS. OR NOT 在 MySQL 中的表现 LIKE 之注意事项 运用通配符的技巧 Understanding Order of Evaluation 与大多数编程语言一样, AND 比 OR 有更高的优先级. Using Parentheses in WHERE Clauses Whenever you write WHERE clauses that use both AND and OR operators, use parent…
终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Manual  /  Backup and Recovery  /  Using mysqldump for Backups  /  Dumping Data in SQL Format with mysqldump 导入也巨简单,因为导出文件是 .sql 直接用 source 就 ok 了. 另外,需要…
限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性. 详细文档:https://dev.mysql.com/doc/refman/8.0/en/user-account-management.html 关于用户的信息都存储在 mysql 数据库下的 user 表中,查看所有用户名: mysql> USE mysql; mysql> SELECT user FROM user; +------------------+ | user | +------------------…