MySQL database basic table - addition, deletion, modification and query (on)

♥️Author : Xiao Liu at Station C

♥️Personal homepage: Xiao Liu's homepage

♥️ Share cloud computing network operation and maintenance classroom notes every day, hard work may not necessarily pay off, but there will be gains, come on! Work hard together for a better life!

♥️The tree is thousands of feet tall, and the fallen leaves return to the roots. Life is not easy, but the true love in the world

foreword

Don't care too much about what others think of you, be yourself, do your own thing well, and walk your own path. Living in the eyes of others is the saddest thing in the world.

Table of contents

MySQL

table operation

1). Query all tables in the current database

2). View the specified table structure

3). Query the table creation statement of the specified table

​edit

 4). Create table structure

Table Operations - Data Types

1). Numeric type

2). String type

3). Date time type

 Table operation - case


MySQL

ySQL is a relational database management system developed by the Swedish company MySQL AB , which is a product of Oracle . MySQL is one of the most popular relational database management systems . In terms of WEB applications, MySQL is one of the best RDBMS (Relational Database Management System, relational database management system ) application software.

MySQL is a relational database management system. Relational databases store data in different tables instead of putting all data in one big warehouse, which increases speed and improves flexibility.

The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software adopts a dual authorization policy, which is divided into community edition and commercial edition . Because of its small size, fast speed, low overall cost of ownership, especially the open source feature, MySQL is generally chosen as the website for the development of small, medium and large websites. database .

table operation

  Table Operations - Query Creation

1). Query all tables in the current database

1  show tables; 
For example , we can switch to the system database sys and view all table structures in the system database.
use sys;
show tables;

2). View the specified table structure

desc 表名 ;
Through this command, we can view the fields of the specified table, the type of the field, whether it can be NULL , whether there is a default value, etc.

3). Query the table creation statement of the specified table

show create table 表名 ; 1
Through this command, it is mainly used to view the table creation statement, and some parameters will be queried when we create the table without specifying
To, because this part is the default value of the database, such as: storage engine, character set, etc.

 4). Create a table structure

1    CREATE TABLE 表名(
2    字段1 字段1类型 [ COMMENT 字段1注释 ],
3    字段2 字段2类型 [COMMENT 字段2注释 ],
4    字段3 字段3类型 [COMMENT 字段3注释 ],
5    ......
6    字段n 字段n类型 [COMMENT 字段n注释 ]
7    ) [ COMMENT 表注释 ] ;
Note : parameters within [...] are optional, there is no comma after the last field
For example, we create a table tb_user , the corresponding structure is as follows, then the table creation statement is

1    create table tb_user(
2    id int comment '编号',
3    name varchar(50) comment '姓名',
4    age int comment '年龄',
5    gender varchar(1) comment '性别'
6    ) comment '用户表';

Table Operations - Data Types

In the above table creation statement, we used int and varchar when specifying the data type of the field . So in MySQL , besides the above data types, what other common data types are there? Next , let's introduce the data types of MySQL in detail . There are many data types in MySQL , which are mainly divided into three categories: numeric type, string type, and date time type.

1). Numerical type

 

1    如:
2    1). 年龄字段 -- 不会出现负数, 而且人的年龄不会太大
3    age tinyint unsigned
4    2). 分数 -- 总分100分, 最多出现一位小数
5    score double(4,1)

2) .String type

Both char and varchar can describe strings, char is a fixed-length string, how many characters are occupied by the specified length, and
The length of the field value is irrelevant. And varchar is a variable-length string, and the specified length is the maximum occupied length. Relatively speaking, the character of char
could be higher.
1    如:
2    1). 用户名 username ------> 长度不定, 最长不会超过50
3    username varchar(50)
4    2). 性别 gender ---------> 存储值, 不是男,就是女
5    gender char(1)
6    3). 手机号 phone --------> 固定长度为11
7    phone char(11)

3) .Date time type

1    如:
2    1). 生日字段 birthday
3    birthday date
4    2). 创建时间 createtime
5    createtime datetime

 Table operation - case

Design an employee information form with the following requirements:
1. Number (pure numbers)
2. Employee ID ( string type, length not exceeding 10 digits )
3. Employee name (string type, no more than 10 characters in length)
4. Gender (male / female, store a Chinese character)
5. Age (normal age, it is impossible to store negative numbers)
6. ID number (the ID number of the second generation is 18 digits, and there are characters like X in the ID card)
7. Joining time (Year, Month, and Day are acceptable)
The corresponding table creation statement is as follows :
1    create table emp(
2    id int comment '编号',
3    workno varchar(10) comment '工号',
4    name varchar(10) comment '姓名',
5    gender char(1) comment '性别',
6    age tinyint unsigned comment '年龄',
7    idcard char(18) comment '身份证号',
8    entrydate date comment '入职时间'
9    ) comment '员工表';
After the SQL statement is written, you can execute the SQL in the MySQL command line , and then query the table structure information through the desc command

♥️Following is the driving force for my creation

♥️Like, is the greatest recognition for me

♥️This is Xiaoliu, I am inspiring to do every article well, thank you everyone

Guess you like

Origin blog.csdn.net/lzl10211345/article/details/130527324
Recommended