当前位置:网站首页>MySQL Syntax Basics
MySQL Syntax Basics
2022-08-01 20:35:00 【Come to the pot】
目录
数据库操作:
1. 创建数据库: create database 数据库名;
2. 查看所以数据库:show databases;
3, 选中数据库:use 数据库名;
4, 删除数据库:drop database 数据库名;
表操作:
1. 创建表:create table 表名(列名 类型 , 列名 类型);
2. 查看当前数据库中的所有表:show tables;
3. 选中数据库:use 数据名;
4, 删除数据库:drop database 数据库名;
1. 常用数据类型
1.1 数值类型
数值类型可以指定为无符号(unsigned ),but not recommended
数据类型 | 大小 | 说明 | 对应java类型 |
---|---|---|---|
bit[((M)] | M指定位数,默认1 | 二进制数,M范围(1-64) 存储数值范围0~2^M-1 | 常用Boolean对应bit,此时默认1位,存0或1 |
tinyint | 1字节 | Byte | |
smallint | 2字节 | Short | |
int | 4字节 | Integer | |
bigint | 8字节 | long | |
float(M,D) | 4字节 | Mlength of significant digits D小数点后的位数 发生精度丢失 | Float |
double(M,D) | 8字节 | 同上 | Double |
decimal(M,D) | M/D最大值+2 | 双精度 Variable-length space storage similar to strings 优点:误差小 缺点:计算效率低,storage space becomes larger | BigDecimal |
numeric(M,D) | M/D最大值+2 | 同上 | BigDecimal |
1.2 字符串类型
数据类型 | 大小 | 说明 | 对应java类型 |
---|---|---|---|
varchar(SIZE) | 0-65535字节 | 可变长度字符串 SIZE表示最大长度 String representing at most a few characters(不是字节) | String |
text | 0-65535字节 | 长文本数据 | String |
mediumtext | 0-16777215字节 | 中等长度文本数据 | String |
blob | 0-65535字节 | text length data in binary form | byte[] |
1.3 日期类型
数据类型 | 大小 | 说明 | 对应java类型 |
---|---|---|---|
datetime | 8字节 | 范围1000~9999年 不会进行时区的检索及转换 | java.util.Date java.sql.Timestamp |
timestamp | 4字节 | 范围1970~2038年 自动检索当前时区并进行转换 | 同上 |
2. 数据库的操作
say an inputSQL代码技巧
(1)使用上下方向键,Can find previous or nextsql语句
(2)如果有一个sqlhalf of the sentence,I don't want to continue,可以按Crtl+cterminate this statement(this is not a copy!!!)
2.1 显示数据库
show databases;
这行代码,also designedThe interaction between the client and the server
2.2 创建数据库
create database 数据名;
(1)Cannot create a database with the same name
(2)不能以sql中的关键字命名 数据库/表/列
(If you must use keywords,backticks can be added` ` (键盘数字1旁边的键))
(3) database can be created like thiscreate database if not exists 数据库名;
(The advantage is that there will be no error,No matter to create success)
(4)也可以指定数据库采用的字符集,指定数据库字符集的校验规则
(1) 需要注意If the database already exists in the server,continue to create,就会创建失败
(2) and when creating the database,The name of the database cannot be a keyword either
如果必须要使用,可以加反引号` `(键盘上数字1旁边的键)
(3)也可以这样输入sql语句创建数据库
create database if not exists 数据库名;
You can see that there is more than before if not exists,这样写的好处是
如果服务器中没有,就创建
如果服务器中有,就不影响(不会报错)
The role is, for example, when writing code,without writing in the console,Instead do batch execution in one file,Wouldn't an error shall be terminated
(4)You can also specify the character set used by the database,指定数据库字符集的校验规则
The default character set for data is,拉丁文(不支持汉字)
Other character sets areascii、unicode、GBK、utf8(Mainstream character encoding uft8mb4)
2.3 使用数据库
use 数据库名;
After selecting the database,You can work with this library
2.4 删除数据库
drop database 数据库名;
3. 表的操作
Before any operation on the table,Database must be selected first
3.1 查看当前数据库中的表
show tables;
3.2 创建表
create table 表名 (列名 类型 , 列名 类型);
(1) 类型在后,列名在前
(2)Comments can also be added(comment ‘注释’ 或者 -- '注释')
(3)If the table creation statement is long,It can also be divided into multi-line statements to write
(1)Creating tables requires attention,Tables with the same name cannot exist in the same database,And the table name can't be a keyword either(如果非要使用,加反引号` `)
(2)can be annotatedcomment ‘注释’ 或者 -- '注释'
(3) If the statement is long when creating the table,可以把sqlThe statement is divided into multiple lines to write,更美观(Can be written in a text file)
3.3 查看指定表结构
desc 表名;
3.4 删除表
drop table 表名;
Be careful when deleting databases and deleting tables!!!
边栏推荐
猜你喜欢
MongoDB快速上手
Imitation cattle forum project
【Untitled】
Little data on how to learn?Jida latest small learning data review, 26 PDF page covers the 269 - page document small data learning theory, method and application are expounded
STAHL触摸屏维修一体机显示屏ET-316-TX-TFT常见故障
4.1 配置Mysql与注册登录模块
[Personal Work] Remember - Serial Logging Tool
卷积神经网络(CNN)mnist数字识别-Tensorflow
【torch】张量乘法:matmul,einsum
Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data
随机推荐
myid file is missing
【节能学院】推进农业水价综合改革的意见解读
KDD2022 | Self-Supervised Hypergraph Transformer Recommendation System
idea插件generateAllSetMethod一键生成set/get方法以及bean对象转换
Redis 做签到统计
通俗解释:什么是临床预测模型
Buttons with good user experience should not have hover state on mobile phones
Does LabVIEW really close the COM port using VISA Close?
Custom command to get focus
使用常见问题解答软件的好处有哪些?
我的驾照考试笔记(4)
SIPp 安装及使用
Where should I prepare for the PMP exam in September?
多线程之生产者与消费者
【kali-信息收集】(1.4)识别活跃的主机/查看打开的端口:Nmap(网络映射器工具)
有点奇怪!访问目的网址,主机能容器却不行
WhatsApp群发实战分享——WhatsApp Business API账号
我的驾照考试笔记(2)
【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
【kali-信息收集】(1.6)服务的指纹识别:Nmap、Amap