Mysql权威指南读书笔记(四)_MySQL
第三章,MySQL的语法及其使用
先看看MySQL支持的SQL语句的分类
1, 数据库的选取,创建,丢弃和变更
use
create database
drap database
alter database
2, 数据表和索引的创建,变更和丢弃
create table
drop table
create index
drop index
alter index
3, 从数据表检索信息
select
union
4, 事务处理
begin
commit
rollback
set autocommit
5, 对数据表里面的信息进行修改
delete
insert
load data
replace
update
6, 管理型命令
flush
grant
revoke
一,命名规则
1MySQL允许用在名字中的系统字符.
任何字母数字加上”_” 或 “$”
2名字的长度.
数据库,数据表,数据列,索引等名字最多64个字母
256别名最多256个字母
3名字的限定符
依据不同的上下文,有时需要给某些名字加上某个限制:如数据列的全限定,部分限定,以及无限制.这一点比较容易理解
select * from db_name.tbl_name…
二,MySQL中的大小写问题
关键字和函数名:不区别
数据库名数据表名:根据服务器主机系统而定
数据列名索引名:不区别
别名:区别大小写
一般来说,不管系统是否区分数据库名和数据表名中的字母大小写情况,我们都应该在同一个查询语句里面以前后一致的字母大小写形式来写出这些名字,这是一个非常好的编程习惯。
三,MySQL支持的名种数据表类型详解
1,ISAM数据表
这是3.23版本之前的MySQL支特的唯一一种表类型,目前己经过时,MyIASM处理程库逐步取代了ISAM处理程序,这种老式的表类型己经没有人在用了
2,MyIASM数据表
? 这是目前中MySQL默认使用的数据表类型。其优点是
? 如果主机操作系统支持大尺寸文件,数据表长度就能够很大,就能客纳更多的数据.
? 数据表内容独立于硬件也就是说可以把数据表在机器之间随意拷贝
? 提高了索引方面的功能
? 提供了更好的索引键压缩效果
? auto_incremnet能力加强
? 改进了对数据表的完整性检查机制
? 支持进行fulltext全文本搜索
3,Merge数据表
这是一种把相同结构的MyIASM数据表组织为一个逻辑单元的方法
4,HEAP数据表
这是一种使用内存的数据表,而且各个数据行的长度固定,这两个特性使得这种类型数据表的检索速度非常快,作为一种临时性的数据表,HEAP在某些特定情况下很有用。
5,BDB数据表
这种数据表支持事务处理机制
具有良好的并发性能
6,InnoBDB数据表
这是最近加入MySQL的数据表类型,有许多新的特性
支持事务处理机制
崩溃后能够立刻恢复
支持外键功能,包括级联删除
具有并发功能
7这种数据表在硬盘上的文件存储方式
IASM Frm isd ism
MyISAM Frm myd myi
Merge Frm mrg
Heap Frm
BDB Frm db
InnoBDB frm
8数据表的可移植性
通用方法:吧数据表的内容导出到一个文本文件中,然后拷贝到目的地硬盘上,在用脚本加载到数据库里面,这是首先我们应该掌握的方法。但就文件层次的操作来说,某些数据表是可以单独拷贝的。看表了
ISAM No
MyIASM Yes
BDB No
InnoBDB Yes
四,索引的初步知识
1,索引是加快数据表内容访问性能的基本手段,其基本特性:
为可以索引单独的数据列也可以构造包含多个数据列的复合索引
索引可以包含重复键值
可以为一个数据表建立多个索引
2,不同的数据表有着不同的索引特性使用的时候需要区别对待
3,如何创建索引
①用alter table命令创建索引
②用create index 命令创建索引
③在create table 时创建索引
五,变更数据表的结构
当发现某个数据表的结构己经不能满足我们的使用要求时,就要对其结构进行变更.可能需要这个数据表存放比以前更多的信息;也可能是这个数据表里面的某些信息己经没用;了或许是现有的某个数据列宽度太窄…在这些情况下都要用到alter 语匀
1,重新命名数据表
alter table A rename to B //数据表A改名为B
rename table A to B //数据表A改名为B
rename A toC,B to A,C to A //数据表A和数据表B互换名字
alter table S.A rename to T.A //数据库S里面的表A移动到数据库B里面
rename table S.A to T.A //数据库S里面的表A移动到数据库B里面
2,改变数据列的类型
我们现在要把数据表A里面的一个smallint unsigned类型的数据列I再次改动为 mediumint unsigned 类型
alter table A motify I mediumint unsigned
alter table A change I I mediumint unsigned
注意change子句的特点:不仅能够改变数据列的类型,还能改变数据列的名字。这是modify子句所不能完成的。下面就把这个数据列改名了。
alter table A change I J mediumint unsigned
3,将数据表由可变长度数据行转变成固定长度数据行
有的时候为了提高性能,需要做这样的转变,但有一点需要注意:必须用同一条alter命令来一次改变所有的数据列,不能仅仅改变一个数据列!举例如下:
create table A(name varchar(40),address varchar(80))
我们开始修改命令就应该是:
alter table A modify name char(40),modify address char(80);
4,将数据表由固定长度数据行转变成可变长度数据行
如果觉得空间利用率不高,那就需要再转变回来,这个就很简单了,没有特别要求
alter table A modify name varchar(40)
5,转换数据表类型
我们知道,MySQL数据库存在多种数据表类型,但每一种类型的特性并不相同。
如果你想让你的数据表支持事务处理机制。那就必须把它搞成BDB或innoBDB格式
alter table A type= BDB
alter table A type= InnoBDB

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL is a common relational database that is a core component of many websites and applications. As the amount of data becomes larger and larger, how to optimize the performance of MySQL becomes particularly important. One of the key areas is the compression of data tables. In this article we will introduce the data table compression technology in MySQL. Compressed tables and non-compressed tables There are two types of data tables in MySQL: compressed tables and non-compressed tables. Uncompressed tables are MySQL's default table type, which use fixed-length row format to store data. This means data

MySQL is a very popular open source relational database management system that supports complete DDL (data definition language) operations. DDL is a language used to define and manage various data objects in the database, including data tables, views, indexes, etc. It is very important for database administrators and developers to be proficient in DDL operation technology of data tables in MySQL. This article will introduce in detail the technology and methods of DDL operation of data tables in MySQL, and provide practical operation examples. 1. Create a data table. Creating a data table is in DDL.

MySQL is an open source relational database management system. Its basic functions are excellent in database design, data storage and management. In MySQL, the data table is the most basic unit of data storage. In practical applications, data table reloading is a very common operating technique, which can help us improve the operating efficiency of the database and improve the stability of the system. This article will introduce this operation technique in detail from the concepts, principles and practical applications of data table overloading in MySQL. 1. What is data table overloading? Data table overloading is

MySQL modifies the data table: 1. First check all tables in the database, the code is: "SHOW TABLES;"; 2. Modify the table name, the code is: "ALTER TABLE old table name RENAME [TO] new table name;". 3. Check whether the table name is modified successfully. The code is: "SHOW TABLES;"

Introduction to the method of using MySQL's AVG function to calculate the average value of numeric columns in a data table: MySQL is an open source relational database management system with a wealth of built-in functions to process and calculate data. Among them, the AVG function is a function used to calculate the average of a numeric column. This article will introduce how to use the AVG function to calculate the average value of numeric columns in a MySQL data table, and provide relevant code examples. 1. Create a sample data table First, we need to create a sample data table for demonstration. Suppose we have a file called

When we finish reading a book, we all write a reading note. Do we all write as we wish? In fact, a qualified reading note has a thinking process. The editor below shares with you an xmind reading note Chinese thinking Map, you can draw a reading note that is more suitable for you based on the mind map. 1. Reading notes: 1. Record and analyze according to chapters. 2. Record and analyze according to the timeline/story line. 3. Record according to characters. 4. Free recording and analysis. 2. Open [XMind], create a new [Blank Picture], and first enter the target in [Central Topic]: Journey to the West. 3. [Right-click] on the central topic, select [Insert]-Tag, and then enter the author. 4. Add [branch topic]: (1) Main characters. Insert again

Many friends expressed that they want to know how to change motor vehicle contact information in the traffic control 12123 software. The operation method is brought to you below. Friends who are interested can take a look with me. 1. After opening the traffic control 12123 software on your mobile phone and entering the interface, click "More" in the upper options. After entering the business center page, browse to the bottom of the "Motor Vehicle Business" option, find and click "Change Motor Vehicle Contact Information" ” to turn on this feature. 3. Click the "Query" button on the new page. 4. Click the "Read and Agree" button below on the business instructions page. 5. Click "Change registered mobile phone number" after the page jumps. 6. At this time, you will be prompted that identity authentication is required. After selecting a method to enter, you can change the new contact information.

How to use thinkorm to implement related queries between data tables Introduction: During database development, we often encounter situations where we need to perform related queries between multiple data tables. Using thinkorm, an excellent database ORM framework, you can easily implement associated queries of data tables and improve development efficiency. This article will introduce how to use thinkorm to implement related queries between data tables, and provide code examples to help readers better understand. 1. Basic concepts Before performing related queries, you first need to understand th
