当前位置:网站首页>6、 Data definition language of MySQL (1)
6、 Data definition language of MySQL (1)
2022-07-03 10:34:00 【sherry 96】

List of articles
Preface
This section introduces MySQL Medium DDL( Data definition language ), The content mainly includes the management of data definition language library 、 The management of the table 、 Data types and common constraints ( The following section describes it separately ) The content such as .
Library management
establish (create)、 modify (alter)、 Delete (drop)
- Library creation (create)
grammar
create database 【if not exists】 Library name 【character set Character set name 】;
- Modification of the library (alter)
grammar
alter database Library name character set Character set name ;You can change the character set of the library :
ALTER DATEBASE books CHARACTER SET gbk;
- Deletion of Library
grammar
drop database 【if exists】 Library name ;
The management of the table
establish (create)、 modify (alter)、 Delete (drop)
- The creation of a table (create)
grammar
create table 【if not exists】 Table name (
Field name Field type 【 constraint 】,
Field name Field type 【 constraint 】,
…
Field name Field type 【 constraint 】
)
- The modification of table
① Add columns
alter table Table name add column Name type 【first | after Field name 】;
② Modify the type or constraint of the column
alter table Table name modify column Name new type 【 New constraint 】;
③ Change column names
alter table Table name change column Old column names New column names type ;
④ Delete column
alter table Table name drop column Name ;
⑤ Modify the name of the table
alter table Table name rename 【to】 The new name of the table ;
- The deletion of the table
grammar
drop table 【if exists】 Table name ;
- Replication of tables
① Copy the structure of the table
create table Table name like Old table ;
② Copy the structure of the table + data
create table Table name
select Query list from Old table 【where Screening 】;
🧒 data type
- Numerical type
① integer
| type | byte |
|---|---|
| tinyint | 1 |
| smallint | 2 |
| mediumint | 3 |
| int/integer | 4 |
| bigint | 8 |
characteristic
① Both unsigned and signed can be set , Default signed , adopt unsigned Set up unsigned
② If it's out of range , Will be submitted to the out or range abnormal , Insert threshold
③ The length may not be specified , There will be a length by default
The length represents the maximum width of the display , If not enough, use... On the left 0 fill , But it needs to match zerofill , And default to unsigned integer
② floating-point
| Fixed-point number | decimal(M,D) |
|---|---|
| Floating point numbers | float(M,D) double(M,D) |
characteristic
①M Represents the integral part + The number of decimal parts ,D Represents the decimal part
② If you go out of range , Then newspaper out or range abnormal , And insert the critical value
③M and D All can be omitted , But for fixed-point numbers ,M The default is 10,D The default is 0
④ If the accuracy is high , The fixed-point number is preferred
Character
char 、varchar、binary、varbinary、enum、set、text、blob
== Two... Are often used ==:
char: Fixed length characters , It's written as char(M), The maximum length cannot exceed M, among M It can be omitted , The default is 1
varchar: Variable length characters , It's written as varchar(M), The maximum length cannot exceed M, among M Don't omitDate type
year year
date date
time Time
datetime date + Time : byte 8
timestamp date + Time : byte 4 More vulnerable to time zone 、 Grammatical pattern 、 The impact of the version , Better reflect the real time in the current time zone
summary
This section mainly introduces MySQL Data definition language in , There are many common constraints , It will be introduced separately in the next section , Welcome friends to pay attention and learn !

边栏推荐
- Step 1: teach you to trace the IP address of [phishing email]
- Out of the box high color background system
- 20220607其他:两整数之和
- 神经网络入门之预备知识(PyTorch)
- Raspberry pie 4B installs yolov5 to achieve real-time target detection
- Implementation of "quick start electronic" window dragging
- Hands on deep learning pytorch version exercise solution-3.3 simple implementation of linear regression
- Rewrite Boston house price forecast task (using paddlepaddlepaddle)
- Seata分布式事务失效,不生效(事务不回滚)的常见场景
- 20220606 Mathematics: fraction to decimal
猜你喜欢

A super cool background permission management system

What did I read in order to understand the to do list

权重衰退(PyTorch)

ECMAScript -- "ES6 syntax specification # Day1
![[C question set] of Ⅵ](/img/49/eb31cd26f7efbc4d57f17dc1321092.jpg)
[C question set] of Ⅵ

Configure opencv in QT Creator

Opencv+dlib to change the face of Mona Lisa

『快速入门electron』之实现窗口拖拽
![[LZY learning notes -dive into deep learning] math preparation 2.5-2.7](/img/57/579357f1a07dbe179f355c4a80ae27.jpg)
[LZY learning notes -dive into deep learning] math preparation 2.5-2.7

EFFICIENT PROBABILISTIC LOGIC REASONING WITH GRAPH NEURAL NETWORKS
随机推荐
What useful materials have I learned from when installing QT
Convolutional neural network (CNN) learning notes (own understanding + own code) - deep learning
Stroke prediction: Bayesian
Several problems encountered in installing MySQL under MAC system
20220603 Mathematics: pow (x, n)
Leetcode - 1172 plate stack (Design - list + small top pile + stack))
3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
Leetcode - 706 design hash mapping (Design)*
重写波士顿房价预测任务(使用飞桨paddlepaddle)
安装yolov3(Anaconda)
Leetcode刷题---189
Numpy Foundation
Implementation of "quick start electronic" window dragging
Timo background management system
深度学习入门之线性回归(PyTorch)
Deep Reinforcement learning with PyTorch
侯捷——STL源码剖析 笔记
Out of the box high color background system
Leetcode刷题---852
一步教你溯源【钓鱼邮件】的IP地址