MySQL Crash Course #01# Chapter 1. 2 概念. Primary key

索引

书的第一章介绍一些基本的概念。理解数据库是掌握 MySQL 非常重要的一个部分。

 第二章简单介绍了 MySQL 以及若干个 MySQL工具,熟练掌握 mysql Command-Line Utility 就行了。

database 

The term database is used in many different ways, but for our purposes a database is a collection of data stored in some organized fashion

People often use the term database to refer to the database software they are running. This is incorrect, and it is a source of much confusion. Database software is actually called the Database Management System (or DBMS). The database is the container created and manipulated via the DBMS. A database might be a file stored on a hard drive, but it might not. And for the most part this is not even significant as you never access a database directly anyway; you always use the DBMS and it accesses the database for you.

 

table

information

filing cabinet 文件柜

toss it in a drawer 把它扔在抽屉里

you create files within the filing cabinet 你在文件柜内创建文件

and then you file related data in specific files. 然后在特定文件中提交相关数据。

In the database world, that file is called a table.
View Code

 The key here is that the data stored in the table is one type of data or one list. You would never store a list of customers and a list of orders in the same database table. Doing so would make subsequent retrieval and access difficult. Rather, you'd create two tables, one for each list.、、

 

schema

Tables have characteristics and properties that define how data is stored in them. These include information about what data may be stored, how it is broken up, how individual pieces of information are named, and much more. This set of information that describes a table is known as a schema, and schema are used to describe specific tables within a database, as well as entire databases (and the relationship between tables in them, if any).

 

Columns and Datatypes

A single field in a table. All tables are made up of one or more columns.

Tables are made up of columns.

Breaking Up Data It is extremely important to break data into multiple columns correctly. For example, city, state, and ZIP Code should always be separate columns. By breaking these out, it becomes possible to sort or filter data by specific columns (for example, to find all customers in a particular state or in a particular city). If city and state are combined into one column, it would be extremely difficult to sort or filter by state.

 

Primary Key 

A column (or set of columns) whose values uniquely identify every row in a table.

主键值应该可以唯一标识一条记录并且是非空的。书中提到,虽然对于一张表而言主键不是硬性需要的,但是我们应该“总是定义主键”。

关于主键的三条普遍接受的最佳实践:

  • Don't update values in primary key columns.

  • Don't reuse values in primary key columns.

  • Don't use values that might change in primary key columns. (For example, when you use a name as a primary key to identify a supplier, you would have to change the primary key when the supplier merges and changes its name.)

As explained, it is the database software (DBMS or Database Management System) that actually does all the work of storing, retrieving, managing, and manipulating data. MySQL is a DBMS; that is, it is database software.

原文地址:https://www.cnblogs.com/xkxf/p/8619948.html