MySQL-01 DDL、DML、DCL常用SQL

DDL-Date Definition Language#

对库操作
# 删库语句
drop database if exists study;
# 建库语句
create database if not exists study default charset utf8mb4;
# 查看所有数据库
show databases ;
# 使用指定数据库
use study;
# 查看正在使用哪个数据库
select database();
建表操作
create table if not exists student
(
    id        varchar(16) primary key comment '编号',
    name      varchar(8) not null comment '姓名',
    age       tinyint unsigned comment '年龄',
    gender    int(1) default 0 comment '性别',
    exam_id   varchar(12) unique comment '准考证号',
    course_id varchar(2) comment '课程编号'
) comment '学生表';


create table course
(
    id          int(2) auto_increment comment '课程编号' primary key,
    course_name varchar(4) comment '课程名称'
) comment '课程表';

create table course_student
(
    id         int(4) auto_increment comment '主键' primary key,
    course_id  int(2) comment '课程id',
    student_id varchar(16) not null comment '学生id',
    constraint fk_course foreign key (course_id) references course (id) on update cascade on delete set null,
    constraint fk_stu foreign key (student_id) references student (id) on update cascade on delete cascade
) comment '学生课程中间表';
知识截图



posted @   WinSalty  阅读(33)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示
主题色彩