avatar

skv Blog

欢迎来到skv的博客🤯

  • 首页
  • 订阅
  • 归档
  • 友链
  • 关于
主页 MySQL速查
文章

MySQL速查

发表于 2024-04-14 更新于 2024-04- 14
作者 Administrator
9~12 分钟 阅读

数据库

增

create database db_name;

删

drop database db_name;

改

use db_name;

查

show database;
show create database db_name;

数据表

增

create table tb_name (column1 datatype, column2 datatype, column3 datatype, ...);

例:
create table example_table (
    id int auto_increment primary key comment '主键,自增字段',
    name varchar(50) not null comment '字符串类型,不为空',
    age int comment '整数类型',
    email varchar(100) unique comment '字符串类型,唯一索引',
    birth_date date comment '日期类型',
    registration_date timestamp default current_timestamp comment '时间戳类型,默认为当前时间',
    is_active tinyint(1) default 1 comment '布尔类型,默认为 1',
    salary decimal(10, 2) comment '十进制类型,包含小数点',
    gender enum('Male', 'Female', 'Other') comment '枚举类型,只能取 Male, Female, Other 中的一个值',
    smallint_column smallint comment '小整数类型',
    mediumint_column mediumint comment '中等整数类型',
    bigint_column bigint comment '大整数类型',
    float_column float(10, 6) comment '浮点类型,精度为10,小数位数为6',
    double_column double(15, 8) comment '双精度浮点类型,精度为15,小数位数为8',
    char_column char(10) comment '固定长度字符串类型',
    text_column text comment '文本类型,适用于存储大量文本数据',
    blob_column blob comment '二进制大对象,适用于存储大量二进制数据',
    boolean_column boolean comment '布尔类型,可存储 TRUE 或 FALSE',
    json_column json comment 'JSON 类型,用于存储 JSON 数据',
    department_id int comment '外键,引用了另一个表中的 id 字段',
    foreign key (department_id) references departments(id)
);

删

drop table tb_name;

改

alter table tb_name add column_name datatype;
alter table tb_name drop column column_name;

查

show tables;
desc tb_name;
show create table tb_name;

数据

增

insert into tb_name (column1, column2, column3, ...) values (value1, value2, value3, ...);

删

delete from tb_name where condition;

truncate table tb_name;

改

update tb_name set column1 = value1, column2 = value2, ... where condition;

查

select column1, column2, ... from tb_name where condition;

默认分类
速查
许可协议:  CC BY 4.0
分享

相关文章

4月 11, 2024

命令速查

pip pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip freeze > re

10月 16, 2025

一些好用的Java第三方库

Commons-io 开发者:Apache 简述:简化文件和流操作的库 <!-- https://mvnrepository.com/artifact/commons-io/commons-io --> <dependency> <groupId>commons-io</groupId>

9月 18, 2025

Java命名规范

包 全小写+域名倒置 package com.denox.java_demo.entity; package com.denox.java_demo.util; 类 大驼峰命名法:每个单词首字母大写 class User {} class UserStudent {} 方法 小驼峰命名法:第二个单

下一篇

加解密速查

上一篇

flex布局笔记

最近更新

  • 命令速查
  • 一些好用的Java第三方库
  • Java命名规范
  • Java学习笔记
  • 张家界学院校园网一键登录

热门标签

前端 Linux 速查 Java 工具 大数据

目录

©2025 skv Blog. 保留部分权利。

使用 Halo 主题 Chirpy