首页 > 数据库 >【MySQL】二级MySQL考试 救场帮助表

【MySQL】二级MySQL考试 救场帮助表

时间:2022-09-26 00:34:10浏览次数:55  
标签:Functions help 22 mysql 救场 MySQL id 考试 name

 

周六去考二级,应用第一题就是添加外键约束

草,写了半天老说语法不对,然后急中生智,觉得默认的库里应该有文档说明表

以下是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

  

 

标签:Functions,help,22,mysql,救场,MySQL,id,考试,name
From: https://www.cnblogs.com/mindzone/p/16729508.html

相关文章

  • 面试官:1亿条数据批量插入 MySQL,哪种方式最快?
    这几天研究mysql优化中查询效率时,发现测试的数据太少(10万级别),利用EXPLAIN比较不同的SQL语句,不能够得到比较有效的测评数据,大多模棱两可,不敢通过这些数据下定论。所......
  • MySQL常用知识点梳理
    删表DROPTABLEIFEXISTS表名;新建表createtable表名(字段名类型约束(逐渐,非空,唯一,默认值),字段名类型约束(逐渐,非空,唯一,默认值),)编码,存储引擎;约束N......
  • 2022-09-25-近60道MySQL经典面试题
    近60道MySQL经典面试题mysql面试常见问题学习整理2.3.17.18.19.20.44未看。1.B树和B+树之间的区别是?为什么mysql使用B+树?一个节点有多个元素;B+树也是排序了的;B+树非叶......
  • MySQL的join算法优化
    在Mysql的实现中,Nested-LoopJoin有3种实现的算法:SimpleNested-LoopJoin:SNLJ,简单嵌套循环连接IndexNested-LoopJoin:INLJ,索引嵌套循环连接BlockNested-LoopJoin:BN......
  • MySQL 的一条语句的执行流程
    分为客户端,服务端,存储引擎三部分。mysql8.0后,取消缓存。1.myisam和innodb的区别。Mysql的InnoDB和MyISAM存储引擎的常见区别如下:锁支持:MyISAM只有表级锁(table-lev......
  • mysql存储引擎
    MySQL存储引擎概述MySQL5.0支持的存储引擎包括MyISAM、InnoDB、BDB、MEMORY、MERGE、EXAMPLE、NDBCluster、ARCHIVE、CSV、BLACKHOLE、FEDERATED等,其中Inno......
  • mysql整理
    mysql整理跨库更新数据UPDATEpmcc_assess.tb_project_infoaTableINNERJOIN(SELECTidasdata_id,uuidasdata_uuidFROMpmcc_contract.tb_cms_contractbTa......
  • mysql函数
    日期函数返回当前日期,只包含年月日selectcurdate()返回当前时间,只包含时分秒selectcurtime()返回当前的日期和时间,年月日时分秒全都包含selectnow()提取......
  • mysql_数据库设计三范式
    设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称为不同的范式,各种范式呈递次规范,越高的范式数据库冗余越小。目前关系数据库有六......
  • mysql事务
    什么是事务一系列有序的数据库操作:要么全部成功要么全部回退到操作前的状态中间状态对其他连接不可见事务的基本操作:|基本操作|说明||:-------------|:-......