当前位置:网站首页>6、 MySQL data definition language (1)
6、 MySQL data definition language (1)
2022-06-22 02:57:00 【xiaoweiwei99】

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 omit
3. Date 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 !

边栏推荐
- import和require在浏览器和node环境下的实现差异
- Game Jam开发周期
- Right and left vertical time axis with serial number
- Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization
- Flink CDC MongoDB Connector 的实现原理和使用实践
- Force buckle 141 Circular linked list
- 圖數據庫ONgDB Release v-1.0.2
- EFCore中的主键
- 【5. 高精度减法】
- 图书馆管理系统(PHP期末报告)
猜你喜欢

Neo4j 技能树正式发布,助你轻松掌握Neo4j图数据库

Day14QProgressBar2021-10-17

最新發布:Neo4j 圖數據科學 GDS 2.0 和 AuraDS GA

Markdown advanced syntax, marktext compatible
![[9. submatrix sum]](/img/97/32f11e2f26a1f313c808fcc1cd27b3.png)
[9. submatrix sum]

Microsoft Internet Explorer was permanently closed on June 15

Figure base de données ongdb version V - 1.0.2

背光模组的基本结构与应用

Dernière publication: neo4j Graph Data Science GDS 2.0 et aurads ga

C ++ Primer 第2章 变量和基本类型 总结
随机推荐
Relative references must start with either “/“, “./“, or “../“.
Typora + picGo 配置图床实现图片自动上传
Conference chat room - development documents
Day18qt signal and slot 2021-10-29
Day14QProgressBar2021-10-17
最热门海量的阿里云盘资源分享
[6. high precision multiplication]
[4. high precision addition]
【3.整数与浮点数二分】
[go language] we should learn the go language in this way ~ a comprehensive learning tutorial on the whole network
Flink CDC MongoDB Connector 的实现原理和使用实践
【2. 归并排序】
Microsoft Internet Explorer was permanently closed on June 15
Deep Copy
The neo4j skill tree was officially released to help you easily master the neo4j map database
ATM simulation system
PMP reference related agile knowledge
UnionPay payment return merchant nignx post request 405
Sword finger offer 57 Next node of binary tree
Architecture and practice of vivo container cluster monitoring system