当前位置:网站首页>Write table of MySQL Foundation (create table)
Write table of MySQL Foundation (create table)
2022-04-23 20:45:00 【Jan York】
Tools
On the market SQL There are many visualization tools , I usually use these two .

Of course ,IDEA It also integrates the database visualization function . In addition to these , also DBeaver、SQLyog wait .
I prefer DataGrip, I'll use this to demonstrate . But this interface doesn't have Navicat It's beautiful , However, I feel that the function is much more powerful .
Write a watch

here , I've created a Demo database .
Let's first understand the syntax of creating tables .
Create table
USE Demo;
# The grammar is as follows
# CREATE TABLE [IF NOT EXISTS] Table name ( Field contents )
CREATE TABLE IF NOT EXISTS class(
Id INT(4) COMMENT 'ID Number ',
Name VARCHAR(10) COMMENT ' full name '
);
IF NOT EXISTS You can omit it .
CREATE TABLE class(
Id INT(4) COMMENT 'ID Number ',
Name VARCHAR(10) COMMENT ' full name '
);
remember **CREATE TABLE** Used to create tables .
Create fields
() Inside are the fields of the table , The format of the written field is as follows .
# Field name value type COMMENT ' Field notes '
Id INT(4) COMMENT 'ID Number ',
Name VARCHAR(10) COMMENT ' full name '
- If the value type is to be set, the length , We can connect... At the back
(), Fill in the length value . COMMENTKeywords are the corresponding notes used to create fields , Remarks must be followed by .
Field constraints and attribute settings
We can set constraints and properties for fields through some keywords .
Id INT(4) COMMENT 'ID Number ' PRIMARY KEY ,
id INT(4) COMMENT 'ID Number ' PRIMARY KEY AUTO_INCREMENT NOT NULL UNIQUE KEY
such as ,PRIMARY KEY Keyword can set the field as the primary key .
Variable position ! The corresponding syntax format is enough , Field data type [ Field properties | constraint ] [ Indexes ] [ Field notes ] .
| Constraints or attributes | explain |
|---|---|
| Primary key constraint | PRIMARY KEY |
| Foreign key constraints | FOREIGN KEY |
| Non empty constraint | NOT NULL |
| Automatic growth | AUTO_INCREMENT |
| Unique constraint | UNIQUE KEY |
| Default constraint | DEFAULT |
For these constraints , If you need to know the detailed function , Please go to the browser to view , Hey !
Common data types
value type
| type | size | purpose |
|---|---|---|
| TINYINT | 1 Bytes | Small integer value |
| SMALLINT | 2 Bytes | Large integer value |
| MEDIUMINT | 3 Bytes | Large integer value |
| INT or INTEGER | 4 Bytes | Large integer value |
| BIGINT | 8 Bytes | Maximum integer value |
| FLOAT | 4 Bytes | Single precision Floating point numbers |
| DOUBLE | 8 Bytes | Double precision Floating point numbers |
| DECIMAL | Yes DECIMAL(M,D) , If M>D, by M+2 Otherwise D+2 | Small value |
The date type
| type | size ( bytes) | Format | purpose |
|---|---|---|---|
| DATE | 3 | YYYY-MM-DD | Date value |
| TIME | 3 | HH:MM:SS | Time value or duration |
| YEAR | 1 | YYYY | The year is worth |
| DATETIME | 8 | YYYY-MM-DD HH:MM:SS | Mix date and time values |
| TIMESTAMP | 4 | YYYYMMDD HHMMSS | Mix date and time values , Time stamp |
String type
| type | size | purpose |
|---|---|---|
| CHAR | 0-255 bytes | Fixed length string |
| VARCHAR | 0-65535 bytes | Variable length string |
| TINYBLOB | 0-255 bytes | No more than 255 Binary string of characters |
| TINYTEXT | 0-255 bytes | Text string |
| BLOB | 0-65 535 bytes | Long text data in binary form |
| TEXT | 0-65 535 bytes | Long text data |
| MEDIUMBLOB | 0-16 777 215 bytes | Medium length text data in binary form |
| MEDIUMTEXT | 0-16 777 215 bytes | Medium length text data |
| LONGBLOB | 0-4 294 967 295 bytes | Maximum text data in binary form |
| LONGTEXT | 0-4 294 967 295 bytes | Large text data |
版权声明
本文为[Jan York]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232039375847.html
边栏推荐
- Leetcode 709, convert to lowercase
- Send email to laravel
- Singleton mode
- LeetCode 116. 填充每个节点的下一个右侧节点指针
- The more you use the computer, the slower it will be? Recovery method of file accidental deletion
- Leetcode 232, queue with stack
- MySQL stored procedures and functions
- 又一款数据分析神器:Polars 真的很强大
- Unity animation creates sequence frame code and generates animationclip
- 100天拿下11K,转岗测试的超全学习指南
猜你喜欢

Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case

Vulnhub DC: 1 penetration notes

MySQL数据库常识之储存引擎

A login and exit component based on token

On IRP from the perspective of source code

Unity solves Z-fighting

电脑越用越慢怎么办?文件误删除恢复方法

LeetCode 994、腐烂的橘子

The ODB model calculates the data and outputs it to excel

Rt-1052 learning notes - GPIO architecture analysis
随机推荐
How to do after winning the new debt? Is it safe to open an account online
bounding box iou
SQL: query duplicate data and delete duplicate data
常用60类图表使用场景、制作工具推荐
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
Unity solves Z-fighting
MySQL基础合集
缓存淘汰算法初步认识(LRU和LFU)
软件测试要怎么学?自学还是培训看完这篇文章你就懂了
Go限制深度遍历目录下文件
UKFslam
Unity animation creates sequence frame code and generates animationclip
三十.什么是vm和vc?
XXXI` Prototype ` displays prototype properties and`__ proto__` Implicit prototype properties
MySQL进阶之表的增删改查
Rt-1052 learning notes - GPIO architecture analysis
[SQL] string series 2: split a string into multiple lines according to specific characters
2021-06-29 C escape character cancellation and use
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
6-5 string - 2 String copy (assignment) (10 points) the C language standard function library includes the strcpy function for string copy (assignment). As an exercise, we write a function with the sam