【MySQL】二级MySQL考试 救场帮助表
周六去考二级,应用第一题就是添加外键约束
草,写了半天老说语法不对,然后急中生智,觉得默认的库里应该有文档说明表
以下是SQL查询过程:
-- 猜测是在mysql库里面
mysql> USE mysql;
Database changed -- 查看这个库下的表
mysql> SHOW TABLES;
+------------------------------------------------------+
| Tables_in_mysql |
+------------------------------------------------------+
| columns_priv |
| component |
| db |
| default_roles |
| engine_cost |
| func |
| general_log |
| global_grants |
| gtid_executed |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| innodb_index_stats |
| innodb_table_stats |
| password_history |
| plugin |
| procs_priv |
| proxies_priv |
| replication_asynchronous_connection_failover |
| replication_asynchronous_connection_failover_managed |
| role_edges |
| server_cost |
| servers |
| slave_master_info |
| slave_relay_log_info |
| slave_worker_info |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+------------------------------------------------------+
35 rows in set (0.46 sec)
然后发现这四张Help表,考试的时候我没关注过分类表
展开查看发现,里面已经说明了MySQL的内容:
mysql> SELECT * FROM help_category;
+------------------+---------------------------------------+--------------------+-----+
| help_category_id | name | parent_category_id | url |
+------------------+---------------------------------------+--------------------+-----+
| 0 | Contents | 0 | |
| 1 | Help Metadata | 0 | |
| 2 | Data Types | 0 | |
| 3 | Administration | 0 | |
| 4 | Functions | 0 | |
| 5 | Enterprise Encryption Functions | 4 | |
| 6 | Language Structure | 0 | |
| 7 | Geographic Features | 0 | |
| 8 | MBR | 7 | |
| 9 | WKT | 7 | |
| 10 | Comparison Operators | 4 | |
| 11 | Logical Operators | 4 | |
| 12 | Flow Control Functions | 4 | |
| 13 | Numeric Functions | 4 | |
| 14 | Date and Time Functions | 4 | |
| 15 | String Functions | 4 | |
| 16 | Cast Functions and Operators | 4 | |
| 17 | XML | 4 | |
| 18 | Bit Functions | 4 | |
| 19 | Encryption Functions | 4 | |
| 20 | Locking Functions | 4 | |
| 21 | Information Functions | 4 | |
| 22 | Spatial Functions | 4 | |
| 23 | WKT Functions | 22 | |
| 24 | WKB Functions | 22 | |
| 25 | Geometry Constructors | 22 | |
| 26 | Geometry Property Functions | 22 | |
| 27 | Point Property Functions | 22 | |
| 28 | LineString Property Functions | 22 | |
| 29 | Polygon Property Functions | 22 | |
| 30 | GeometryCollection Property Functions | 22 | |
| 31 | Geometry Relation Functions | 22 | |
| 32 | MBR Functions | 22 | |
| 33 | GTID | 4 | |
| 34 | Aggregate Functions and Modifiers | 4 | |
| 35 | GROUP BY Functions and Modifiers | 4 | |
| 36 | Window Functions | 4 | |
| 37 | Performance Schema Functions | 4 | |
| 38 | Internal Functions | 4 | |
| 39 | Miscellaneous Functions | 4 | |
| 40 | Data Definition | 0 | |
| 41 | Data Manipulation | 0 | |
| 42 | Transactions | 0 | |
| 43 | Compound Statements | 0 | |
| 44 | Account Management | 0 | |
| 45 | Table Maintenance | 0 | |
| 46 | User-Defined Functions | 0 | |
| 47 | Components | 0 | |
| 48 | Plugins | 0 | |
| 49 | Utility | 0 | |
| 50 | Storage Engines | 0 | |
+------------------+---------------------------------------+--------------------+-----+
51 rows in set (0.05 sec)
因为是关键字或者其他问题,尝试翻查这个关键字帮助表
当时写外键语句是这样:
ALTER TABLE xxx
ADD CONSTRAINT FOREIGN KEY xxx(xxx) REFERENCE xx(xx);
报错提醒发生在 reference这里
所以我当时就搜素两个关键字,外键和引用这两个
mysql> SELECT * FROM help_keyword WHERE `name` LIKE '%reference%';
+-----------------+------------+
| help_keyword_id | name |
+-----------------+------------+
| 653 | REFERENCE |
| 673 | REFERENCES |
+-----------------+------------+
2 rows in set (0.03 sec) mysql> SELECT * FROM help_keyword WHERE `name` LIKE '%FOREIGN%';
+-----------------+---------+
| help_keyword_id | name |
+-----------------+---------+
| 599 | FOREIGN |
+-----------------+---------+
1 row in set (0.02 sec)
然后官方给这个文档帮助表设定的说明关系是,关键字和主题是一个多对多的关系
用一个关系表维护,这里要先看【帮助主题】绑定的【关键字ID】
mysql> SELECT * FROM help_relation WHERE help_keyword_id = 599;
+---------------+-----------------+
| help_topic_id | help_keyword_id |
+---------------+-----------------+
| 508 | 599 |
| 518 | 599 |
| 520 | 599 |
| 521 | 599 |
+---------------+-----------------+
4 rows in set (0.12 sec)
我们还可以再看看之前reference关键字关联的
mysql> SELECT * FROM help_relation WHERE help_keyword_id = 653;
+---------------+-----------------+
| help_topic_id | help_keyword_id |
+---------------+-----------------+
| 519 | 653 |
| 532 | 653 |
+---------------+-----------------+
2 rows in set (0.02 sec) mysql> SELECT * FROM help_relation WHERE help_keyword_id = 673;
+---------------+-----------------+
| help_topic_id | help_keyword_id |
+---------------+-----------------+
| 520 | 673 |
| 521 | 673 |
| 610 | 673 |
+---------------+-----------------+
3 rows in set (0.02 sec)
可以发现599ID 和673ID都有共同两个帮助主题
所以确定是References关键字,然后看看520ID的主题是什么:
由于主题表输出的内容太多,格式完全混乱了,当时考试那个命令终端就是一直刷,还没办法停下
然后先查看主题表的字段:
mysql> DESC help_topic;
+------------------+-------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------------+------+-----+---------+-------+
| help_topic_id | int unsigned | NO | PRI | NULL | |
| name | char(64) | NO | UNI | NULL | |
| help_category_id | smallint unsigned | NO | | NULL | |
| description | text | NO | | NULL | |
| example | text | NO | | NULL | |
| url | text | NO | | NULL | |
+------------------+-------------------+------+-----+---------+-------+
6 rows in set (0.08 sec)
最主要的是example样例和decription描述,但是example查询为空,只能看描述了
mysql> SELECT example FROM help_topic WHERE help_topic_id = 520;
+---------+
| example |
+---------+
| |
+---------+
520ID没找到,就找521,结果一看正好就是这个:
就是少写了S导致的
MySQL supports foreign keys, which permit cross-referencing related
data across tables, and foreign key constraints, which help keep the
related data consistent. A foreign key relationship involves a parent table that holds the
initial column values, and a child table with column values that
reference the parent column values. A foreign key constraint is defined
on the child table. The essential syntax for a defining a foreign key constraint in a
CREATE TABLE or ALTER TABLE statement includes the following: [CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (col_name, ...)
REFERENCES tbl_name (col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option] reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT URL: https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html
【MySQL】二级MySQL考试 救场帮助表的更多相关文章
- mysql的锁--行锁,表锁,乐观锁,悲观锁
一 引言--为什么mysql提供了锁 最近看到了mysql有行锁和表锁两个概念,越想越疑惑.为什么mysql要提供锁机制,而且这种机制不是一个摆设,还有很多人在用.在现代数据库里几乎有事务机制,aci ...
- mysql复习-来源考试
mysql复习- No1 .登录和权限 (一)常用命令1.登录mysqlmysql -h localhost -u root -p 2.重启mysqlservice mysql restart 延 ...
- MySQL的选则字段+联表+判断+排序(order by)
MySQL的选则字段+联表+判断+排序(order by) 两个表:1.成绩单 2.查询名单 目标: 1.选中全部字段,用于输出. 2.成绩单中有很多人的成绩,第一步是希望通过联表,只查查询名单上的人 ...
- MySQL学习笔记02_数据库和表的基本操作
02_1 操作数据库 (1)创建数据库 CREATE DATABASE [IF NOT EXISTS] db_name [create_specification[, create_specifica ...
- MySQL中select * for update锁表的范围
MySQL中select * for update锁表的问题 由于InnoDB预设是Row-Level Lock,所以只有「明确」的指定主键,MySQL才会执行Row lock (只锁住被选取的资料例 ...
- MySQL中select * for update锁表的问题
MySQL中select * for update锁表的问题 由于InnoDB预设是Row-Level Lock,所以只有「明确」的指定主键,MySQL才会执行Row lock (只锁住被选取的资料例 ...
- mysql系统库INFORMATION_SCHEMA,MySQL,TEST,mysql系统表的作用
本文简要说明了MySQL数据库安装好后自带的INFORMATION_SCHEMA,MySQL,TEST三个数据库的用途. 第一个数据库INFORMATION_SCHEMA: 提供了访问数据库元数据的方 ...
- MYSQL中约束及修改数据表
MYSQL中约束及修改数据表 28:约束约束保证数据的完整性和一致性约束分为表级约束和列级约束约束类型包括: NOT NULL(非空约束) PRIMARY KEY(主键约束) UNI ...
- MySQL 如何只导出 指定的表 的表结构和数据 ( 转 )
MySQL 如何只导出 指定的表 的表结构和数据 ( 转 ) 2011-01-04 15:03:33 分类: MySQL MySQL 如何只导出 指定的表 的表结构和数据 导出更个库的表结构如下:my ...
- mysql存储过程之游标遍历数据表
原文:mysql存储过程之游标遍历数据表 今天写一个mysql存储过程,根据自己的需求要遍历一个数据表,因为对存储过程用的不多,语法不甚熟悉,加之存储过程没有调试环境,花了不少时间才慢慢弄好,故留个痕 ...
随机推荐
- 硬件开发笔记(十七):RK3568底板电路串口、485、usb原理图详解
前言 原理图有一些常用电路. 本篇就将集中常用电路分析完,如uart口,涉及usart串口.rs485.usb口. 串口 串行接口简称串口,也称串行通信接口或串行通讯接口(通常指COM接 ...
- docker综合应用
1.容器资源限制 官网文档 https://docs.docker.com/config/containers/resource_constraints/ 2.docker内存限制 -m或者--mem ...
- http的响应码200,404,302,500表示的含义分别是?
200 - 确定.客户端请求已成功 302 - 临时移动转移,请求的内容已临时移动新的位置 404 - 未找到文件或目录 500 - 服务器内部错误
- TiKV 源码分析之 PointGet
作者:来自 vivo 互联网存储研发团队-Guo Xiang 本文介绍了TiDB中最基本的PointGet算子在存储层TiKV中的执行流程. 一.背景介绍 TiDB是一款具有HTAP能力(同时支持在线 ...
- Java泛型对象在http请求和响应对象中的封装
Java泛型对象在http请求和响应对象中的封装 public class MySystemBaseResVo<T> { //注意:类的后面需要带上<T>,否则数据无法封装 p ...
- json字符串忽略null,忽略字段,首字母大写等gson,jackson,fastJson实现demo,T data JSON.parseObject json转换
json字符串忽略null,忽略字段,首字母大写等gson,jackson,fastJson实现demo package com.example.core.mydemo.json.vo; import ...
- 视觉语言跨模态特征语义相似度计算改进--表征空间维度语义依赖感知聚合算法 ACM MM
论文链接:Unlocking the Power of Cross-Dimensional Semantic Dependency for Image-Text Matching (ACM MM23) ...
- Windows下用VS2022编译安装Boost库
Windows下用VS2022编译安装Boost库 下载地址: https://www.boost.org/users/download/ 解压得到如下文件: 编译安装: 打开vs2022命令行工具 ...
- Apache Kylin(三)Kylin上手
Kylin 上手 根据Kylin 官方给出的测试数据,我们实际操作一下 Kylin. 1. 导入 Hive 数据 首先创建一个project,在界面左上角有个"Add Project&quo ...
- uCos 学习:0-有关概念
先说一下UCOSIII:Micrium在2009年推出了UCOSIII,相对于之前的UCOSII版本,在性能上有了进一步的提升,主要是支持时间片轮调度,极短的关中断事件等. 可剥夺多任务管理: 什么是 ...