MySQL Crash Course #10# Chapter 19. Inserting Data
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,
NULL);
Always Use a Columns List As a rule, never use INSERT without explicitly specifying the column list. This will greatly increase the probability that your SQL will continue to function in the event that table changes occur.
Improving Overall Performance
Databases are frequently accessed by multiple clients, and it is MySQL's job to manage which requests are processed and in which order. INSERT operations can be time consuming (especially if there are many indexes to be updated), and this can hurt the performance of SELECT statements that are waiting to be processed.
If data retrieval is of utmost importance (as is usually is), you can instruct MySQL to lower the priority of your INSERT statement by adding the keyword LOW_PRIORITY in between INSERT and INTO, like this:
INSERT LOW_PRIORITY INTO
Incidentally, this also applies to the UPDATE and DELETE statements that you'll learn about in the next chapter.
Inserting Multiple Rows INSTEAD OF Inserting a Single Row
INSERT INTO customers(cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country)
VALUES(
'Pep E. LaPew',
'100 Main Street',
'Los Angeles',
'CA',
'',
'USA'
),
(
'M. Martian',
'42 Galaxy Way',
'New York',
'NY',
'',
'USA'
);
Improving INSERT Performance This technique can improve the performance of your database possessing, as MySQL will process multiple insertions in a single INSERT faster than it will multiple INSERT statements.
Inserting Retrieved Data
INSERT INTO customers(cust_id,
cust_contact,
cust_email,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country)
SELECT cust_id,
cust_contact,
cust_email,
cust_name,
cust_address,
cust_city,
cust_state,
cust_zip,
cust_country
FROM custnew;
PS. 列名可以不对应,列的值类型对应就可以了。
MySQL Crash Course #10# Chapter 19. Inserting Data的更多相关文章
- MySQL Crash Course #13# Chapter 21. Creating and Manipulating Tables
之前 manipulate 表里的数据,现在则是 manipulate 表本身. INDEX 创建多列构成的主键 自动增长的规定 查看上一次插入的自增 id 尽量用默认值替代 NULL 外键不可以跨引 ...
- MySQL Crash Course #04# Chapter 7. 8 AND. OR. IN. NOT. LIKE
索引 AND. OR 运算顺序 IN Operator VS. OR NOT 在 MySQL 中的表现 LIKE 之注意事项 运用通配符的技巧 Understanding Order of Evalu ...
- MySQL Crash Course #11# Chapter 20. Updating and Deleting Data
INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Dele ...
- MySQL Crash Course #05# Chapter 9. 10. 11. 12 正则.函数. API
索引 正则表达式:MySQL only supports a small subset of what is supported in most regular expression implemen ...
- MySQL Crash Course #06# Chapter 13. 14 GROUP BY. 子查询
索引 理解 GROUP BY 过滤数据 vs. 过滤分组 GROUP BY 与 ORDER BY 之不成文的规定 子查询 vs. 联表查询 相关子查询和不相关子查询. 增量构造复杂查询 Always ...
- MySQL Crash Course #12# Chapter 18. Full-Text Searching
INDEX 由于性能.智能结果等多方面原因,在搜索文本时,全文搜索一般要优于通配符和正则表达式,前者为指定列建立索引,以便快速找到对应行,并且将结果集智能排序.启用查询扩展可以让我们得到未必包含关键字 ...
- MySQL Crash Course #02# Chapter 3. 4 通配符. 分页
索引 查看表.文档操作 检索必须知道的两件事 数据演示由谁负责 通配符.非必要不用 检索不同的行 限制结果集.分页查找 运用数据库.表全名 命令后加分号对于很多 DBMS 都不是必要的,但是加了也没有 ...
- MySQL Crash Course #21# Chapter 29.30. Database Maintenance & Improving Performance
终于结束这本书了,最后两章的内容在官方文档中都有详细介绍,简单过一遍.. 首先是数据备份,最简单直接的就是用 mysql 的内置工具 mysqldump MySQL 8.0 Reference Man ...
- MySQL Crash Course #20# Chapter 28. Managing Security
限制用户的操作权限并不是怕有人恶意搞破坏,而是为了减少失误操作的可能性. 详细文档:https://dev.mysql.com/doc/refman/8.0/en/user-account-manag ...
随机推荐
- Zabbix监控Nginx状态信息
首先要检查Nginx是否安装了 http_stub_status_module 模块,通过下面的命令可以看到编译参数.yum安装的默认会带有这个模块. [root@kafka60 ~]# /data/ ...
- Python 之反射和普通方式对比(模拟Web框架)
先模拟一个web页面的选择不同输出不同 vim day8-7.py #!/usr/bin/python # -*- coding:utf-8 -*- import home import accoun ...
- tesseract .net 中使用历程
最近在看文字识别的实例,也查询很多文章,最后还是选定开源的引擎(tesseract3.0.1) 最开始找到的是用微软Office的一个组件实现的,个人感觉不是我想要的(要开源啊才是王道) http:/ ...
- HDU 2037 - 今年暑假不AC - [经典 选择不相交区间 问题]
是一道很经典的选择不相交区间的问题. 关于选择不相交区间,可以参考刘汝佳.也可以参考:http://blog.csdn.net/dgq8211/article/details/7534488 以及模板 ...
- 第九次CSP第四题 - 压缩编码
给定一段文字,已知单词a1, a2, …, an出现的频率分别t1, t2, …, tn.可以用01串给这些单词编码,即将每个单词与一个01串对应,使得任何一个单词的编码(对应的01串)不是另一个单词 ...
- SQL Fundamentals: 子查询 || 行列转换(PIVOT,UNPIVOT,DECODE),设置数据层次(LEVEL...CONNECT BY)
SQL Fundamentals || Oracle SQL语言 子查询(基础) 1.认识子查询 2.WHERE子句中使用子查询 3.在HAVING子句中使用子查询 4.在FROM子句中使用子查询 5 ...
- PostGIS 快速入门(转)
原文:http://live.osgeo.org/zh/quickstart/postgis_quickstart.html PostGIS 是 PostgreSQL 关系数据库的空间操作扩展.它为 ...
- sql优化 性能快速定位
sql server sql性能快速定位 简介 对于写出实现功能的SQL语句和既能实现功能又能保证性能的SQL语句的差别是巨大的.很多时候开发人员仅仅是把精力放在实现所需的功能上,而忽略了其所写代码的 ...
- sql优化 表连接join方式
sql优化核心 是数据库中 解析器+优化器的工作,我觉得主要有以下几个大方面:1>扫表的方法(索引非索引.主键非主键.书签查.索引下推)2>关联表的方法(三种),关键是内存如何利用 ...
- [py]函数中yield多次返回,延迟计算特性-杨辉三角
搞清什么是杨辉三角 每行是一个数组, 第一行: [1] 第二行: [1, 1] 第三行: [1, 2, 2, 1] ... 画的好看点就是,不过没啥卵用 1 / \ 1 1 / \ / \ 1 2 1 ...