Basic concepts of database for beginners

Install MySQL database 8.0 service instance
Install MySQL database 5.7 instance

foreword

This article opens a MySQLdatabase column, which is specially used to record the learning process of the database and the demonstration process of some operations; if you are learning the database like me, MySQLand have some interests and ideas about it, you can pay attention to it and let's work together Learn and progress together.
Some concepts in this article will refer to 《MySQL必知必会》the knowledge in this book, because this book is relatively friendly to beginners, and it MySQLis still very good as a beginner.

1. Understand the database

1.1 Database Basics

In fact, in our daily life, we interact with data all the time, such as shopping on Taobao, searching for information on Baidu, and interacting with people on WeChat. This is the process of using the database; although we are using the database all the time, But if you don't know what kind of technology the database is, or what it is used for, then you need to answer the question of what the database is and what it can be used for.

1.1.1 What is a database

A database is a collection of data stored in some organized way . The easiest way to understand a database is to think of it as a filing cabinet. This filing cabinet is a place to store data, no matter what the data is and how it is organized. .

Database: A container for organized data.

Note: Usually we often say that the MySQL database, its full name is DBMS (database management system), which can be used to create and manage databases. The database can be said to be a file stored on the device, so when we use the database management system, it is A series of operations such as viewing and accessing can be performed on the database under the management system.

1.1.2 What is a table

When we store a piece of clothing, we don't stuff it directly into the cabinet. We usually put it in a certain grid after sorting it out. The storage of files is also put into the file cabinet, which is neat and easy to manage.
In the database world, files are called tables. A table is a structured file for a specific type of data. The table can store personnel information, product information, lists and other sorted information.

table: A structured list of data of a particular type.

Note: The data stored in the table is one type of data or a list. It is recommended to create a database table of one type; if you write different types of content into one table, it is very inconvenient to look back , I can't see what information is recorded in the table.

Table name: Each table will have a name, which is unique. There cannot be two identical table names in one database. Of course, if they are in different databases, the same table name can be used.

1.1.3 Columns and data types

The best way to understand columns is to think of database tables as Excel. I believe everyone has come into contact with Excel tables. There is a field information at the beginning of each column. This field information can be id, name, city, address, zip code, etc. . It is extremely important to correctly decompose the data into multiple columns, and it is also convenient for subsequent lookups on specific columns, or sorting information.

Column: A field in a table. All tables are composed of one or more columns.

Each column in the database has a corresponding data type. The data type defines the type of data that the column can store. This data type can be a number or a string of words, text, characters and other information.

Data type (datatype): The type of data allowed, each table column has a corresponding data type, which limits (or allows) the data stored in the column.

1.1.4 What is a row

The data in the table is stored in rows, and each saved record is stored in its own row, imagined as an Excel table, and the horizontal rows are table rows.

row (row): a record in the table

1.1.5 What is a primary key

Each row in a table should have a column (set of columns) that uniquely identifies itself. A Customers table could use a Customer ID column, an Orders table could use Order IDs, and an Employees table could use Employee IDs.

primary key: A column (set of columns) whose values ​​uniquely distinguish each row in the table.

This column (set of columns) that uniquely identifies each row in the table is called the primary key. A primary key is used to identify a particular row. Without a primary key, updating or deleting specific rows in a table is difficult because there is no safe way to guarantee that only relevant rows are involved.

how to define primary key

Although not all require a primary key, most database personnel should ensure that each table they create has a primary key for future data manipulation and management.

Any column in the table can be used as a primary key, as long as the following conditions are met:

 - 任意两行都不具有相同的主键值;
 - 每个行都必须具有一个主键值(主键列不允许NULL值)

The primary key is usually defined on one column of the table, but this is not required, and multiple columns can be used together as the primary key. When multiple columns are used as the primary key, the above Heavenly Sword must be applied to all columns that constitute the primary key, and the combination of all column values ​​must be unique (but the value of a single column may not be unique).

Best practices for primary keys:
don't update values ​​in primary key columns
don't reuse values ​​in primary key columns
don't use values ​​in primary key columns that might change

1.2 What is SQL

SQL(Structured Query Language) is a language specially used to communicate with the database. SQLUnlike other languages ​​( java), SQL consists of very few words, and this is intentional. The purpose of the design SQLis to do a good job of providing a simple and efficient way to read and write data from the database.

1.2.1 Advantages of SQL

  1. SQL is not a language specific to a particular database vendor. Almost all DBMS support SQL. So learning the SQL language can deal with almost all databases.
  2. SQL is easy to learn. Its sentences are all composed of highly descriptive English words, and there are not too many words.
  3. Although SQL looks simple, it is actually a powerful language, and its language elements can be used flexibly to perform very complex and advanced database operations.

Summarize

Key words meaning
database A container for organized data
table A structured list of data of a particular type
column A field in the table. All tables are composed of one or more columns.
Data type (datatype) Each table column has a corresponding data type, which limits (or allows) the data stored in that column.
row a record in the table
primary key A column (set of columns) whose values ​​uniquely distinguish each row in the table.

The above is the whole content of the article. Understanding these concepts is very helpful for subsequent studies. The main content is the basic knowledge of databases, as well as the introduction and advantages of SQL.
insert image description here

Guess you like

Origin blog.csdn.net/rhn_111/article/details/129477890