当前位置:网站首页>MySQL DDL (data definition language)
MySQL DDL (data definition language)
2022-07-18 14:03:00 【Caught in a rain】
| The notebook |
One 、 Library management
1、 Library creation
Basic grammar :
CREATE DATABASE Library name
When using this grammar , There will be a problem , If this library exists , Then the result will be wrong , To avoid this problem , The following syntax can be used : That is, judge whether the library exists before creating
CREATE DATABASE IF NOT EXISTS Library name ;
2、 Modification of the library
MySQL Direct modification of library name is not supported in , And the process of modification is troublesome . But its character set can be modified .
grammar :
ALTER DATABASE Library name CHARACTER SET Modified character set ;
For example, change it to GBK
ALTER DATABASE Library name CHARACTER SET GBK;
3、 Deletion of Library
DROP DATABASE IF EXISTS Library name ;
Two 、 The management of the table
1、 The creation of a table
create table Table name (
Name The type of the column 【 constraint 】),
Name The type of the column 【( constraint 】),
Name The type of the column 【 constraint 】),
...
Name The type of the column 【 constraint 】
)
2、 The modification of table
① Change column names
ALTER TABLE Table name CHANGE COLUMN Old column names New column names type ;
② Modify the type or constraint of the column name
ALTER TABLE Table name MODIFY Name new type 【 New constraint 】;
③ Add columns
ALTER TABLE Table name ADD COLUMN Name type ;
If you want to add a field to the first field or after the specified field , You can use this syntax :
ALTER TABLE Table name ADD COLUMN Field name type FIRST;
ALTER TABLE Table name ADD COLUMN Field name type AFTER Field name ;
④ 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 ;
among COLUMN Can be omitted
3、 The deletion of the table
DROP TABLE IF EXISTS Table name ;
4、 Replication of tables
① Just copy the structure of the table
CREATE TABLE Copied table name LIKE Table name to be copied ;
② Copy the structure of the table + data
CREATE TABLE Copied table name SELECT *FROM Table name ;
3、 ... and 、 Common data types
1、 integer
MySQL The main types of integers are TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT, Its attribute field can be added with AUTO_INCREMENT Self increasing constraints , The following table lists MySQL The value type in .
2、 Decimal type
It can be subdivided into
Floating point type :FLOAT(4 byte )、DOUBLE(8 byte )
Fixed point number type :DEC、DECIMAL
The accuracy of fixed-point type is relatively high , If the accuracy of the inserted value is required to be high, consider using , Such as currency calculation
3、 Character type
Shorter text :char、varchar
Their differences : among char Characters representing a fixed length ,varchar Represents variable length characters , Use char Efficient than varchar higher , but char Than varchar More space consuming .
Longer text :text、blob
And then there is BINARY and VARBINARY() Used to hold shorter binary )、ENUM type ( Also known as enumeration type )、SET type ( Save collection )
4、 The date type
DATE( Occupy 4 byte )、DATETIME(8 byte )、TIMESTAMP(4 byte )、TIME(3 byte )、YEAR(1 byte )
Four 、 Common constraints
Six constraints :
①NOT NULL : Non empty constraint , To ensure that the value of this field cannot be empty
②DEFAULT: Default constraint , Used to ensure that the field has a default value
③PRIMARY KEY: Primary key constraint , Used to ensure that the value of this field is unique , And not empty
④UNIQUE: Unique constraint , Used to ensure that the value of this field is unique , Can be null
⑤CHECK: Check constraint 【MySQL I won't support it 】
⑥FOREIGN KEY: Foreign key constraints , Used to restrict the relationship between two tables , Add foreign key constraint from table , Used to reference the value of a column in the main table
| notebook |
边栏推荐
- 高数 | 积分中值定理的开闭区间、积分第一中值定理及其推广
- Idea merges dev branch code into master and so on
- npm与node版本不匹配 更新了npm 结果报错node和npm不匹配 怎么退回之前的npm 版本?或者说怎么查看node适配的npm版本
- T100debug operation record
- T100debug操作记录
- Opencv:05 filter
- 【FPGA教程案例25】通过NCO核和除法器实现tan(x)计算
- Simulation volume leetcode [general] 1996 Number of weak characters in the game
- The version of NPM does not match that of node. When the NPM result is updated, an error is reported. How can the previous NPM version be returned? Or how to check the NPM version of node adaptation
- Feign 实现服务间并且调用时传递 header
猜你喜欢

Install MySQL 5.7.23 in Linux

视频处理及编解码硬件系统优化设计

AB controller l36erm_ Communication between two processors

T100自定义应用使用说明(azzi650)

PMP每日一练 | 考试不迷路-7.15

关于XML文件(五)

The digital transformation forum for small and medium-sized enterprises in Shandong Province was successfully held, and Jiuzhou cloud empowers small and medium-sized enterprises to upgrade their digit

University epidemic prevention and control system based on jsp+servlet

XML file delete comments

Enterprise OA system based on SSM, high-quality paper examples, attached source code, database script, project introduction and operation tutorial, Paper Writing Tutorial
随机推荐
文旅夜游项目助力夜间经济发展
积分签到吸引用户的两种低成本做法
二叉树的广度遍历
Reading true questions | reading true questions record 2
Simulation volume leetcode [general] 2013 Detect square
[MySQL] - basic query exercise of database
开源库MusicPlayManager - 封装StarrySky音乐库
Enterprise OA system based on SSM, high-quality paper examples, attached source code, database script, project introduction and operation tutorial, Paper Writing Tutorial
ABBYY FineReader 15标准版OCR文字识别及PDF编辑软工具
Linux中安装mysql 5.7.23
Simulation volume leetcode [general] 1996 Number of weak characters in the game
Box model, document flow, positioning, layout and responsive design
【FPGA教程案例25】通过NCO核和除法器实现tan(x)计算
Thread safety problems and solutions of simpledateformat
Rectangular sort....
【MySQL】——数据库的基本查询练习
Golang --------- xiaoshiniudao gin framework file upload
【深度学习-学习笔记01】
Sword finger offer19 regular expression matching string dynamic programming
Base64 encoding and decoding principle and C language implementation