“This is the 8th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

What is a database

Wikipedia’s definition of a database:

In computing, a database is an organized collection of data stored and accessed electronically from a computer system. Where databases are more complex they are often developed using formal design and modeling techniques.

In computing, a database is an organized collection of data stored and accessed electronically from a computer system. In a computer, we can think of a database as a “filing cabinet” in which the data needs to be stored and organized in a certain way.

DB and DBMS differences:

Many people confuse DB and DBMS, but they are two different things. The DATABASE (DB) refers to the database container. The database Management System (DBMS) is a database management system. The relationship between the two is that a DATABASE DB is a container created and manipulated by a database management system DBMS. In practice, we do not access the database directly, but use the DBMS to access the database.

2. Important concepts of MySQL database

Table 2.1

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

There are two important points from the above concepts:

  • Specific type -> refers to a type such as user information, order information, product information. Table design does not allow mixing of various data types
  • Structured list -> refers to the data that is divided and organized in a structured way according to user requirements, such as user information divided into user name, gender, age and other structured data

Tables in the same database cannot have the same name but in different databases can have the same name

You can view tables in the database using Show tables

A structured listing of the User table

2.2 column

Column: A field in a table. A table consists of one or more columns.

In the above user information table, there are user names, gender columns, age columns, etc., which together make up the user table.

Columns in the MySQL database have corresponding data types. The datatype (datatype) constrains how much data a column can hold. For example, you can prevent character type data from being entered in numeric fields.

You can run the show full columns from the table name command to view specific columns of the table

2.3 line

Row: A record in a table.

Data in a MySQL database is stored as a row, and each piece of data is a row (also known as a record), but the correct unambiguous term is a hang.

2.4 the primary key

Primary key: A column or columns whose value or combination of values uniquely distinguishes each row in a table.

A primary key is like a person’s ID number. It is not duplicated and can be used to mark the person’s identity. It is worth noting that a primary key can be composed of multiple columns.

It can also be viewed through DDL. The PRIMARY KEY is identified by the PRIMARY KEY

CREATE TABLE 'user' (' id 'bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',' name 'varchar(255) NOT NULL COMMENT '主键', 'age' int(11) NOT NULL COMMENT 'age ',' sex 'smallint(1) DEFAULT NULL COMMENT' gender ', PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;Copy the code

Defining a primary key requires two conditions:

  1. Primary key column data does not duplicate
  2. Primary key column data not null

Columns can be primary keys as long as these two conditions are met. It is recommended that primary keys be defined during table design. Having primary keys facilitates data query, deletion, and update. Otherwise, it is relatively troublesome.

Define two specifications that primary keys satisfy:

  1. Primary key values should not be updated
  2. The primary key value should not have business meaning, that is, should not be used for any other business use than as a token

3, how to read SQL

SQL is a contraction of Strucctured Query Language. We can break down S — Q — L when we read SQL, but most of the time we read it in groups. Sequel / [ˈsiː kW ə L]

This link is read online

Fanyi.baidu.com/?aldtype=16…