Show constraints on tables command

后端 未结 8 1265
慢半拍i
慢半拍i 2020-11-29 14:44

I have tables that I\'ve tried setting PK FK relationships on but I want to verify this. How can I show the PK/FK restraints? I saw this manual page, but it does not show ex

8条回答
  •  -上瘾入骨i
    2020-11-29 15:26

    There is also a tool that oracle made called mysqlshow

    If you run it with the --k keys $table_name option it will display the keys.

    SYNOPSIS
       mysqlshow [options] [db_name [tbl_name [col_name]]]
    .......
    .......
    .......
    ·   --keys, -k
       Show table indexes.
    

    example:

    ╰─➤  mysqlshow -h 127.0.0.1 -u root -p --keys database tokens
    Database: database  Table: tokens
    +-----------------+------------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
    | Field           | Type             | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment |
    +-----------------+------------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
    | id              | int(10) unsigned |                    | NO   | PRI |         | auto_increment | select,insert,update,references |         |
    | token           | text             | utf8mb4_unicode_ci | NO   |     |         |                | select,insert,update,references |         |
    | user_id         | int(10) unsigned |                    | NO   | MUL |         |                | select,insert,update,references |         |
    | expires_in      | datetime         |                    | YES  |     |         |                | select,insert,update,references |         |
    | created_at      | timestamp        |                    | YES  |     |         |                | select,insert,update,references |         |
    | updated_at      | timestamp        |                    | YES  |     |         |                | select,insert,update,references |         |
    +-----------------+------------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
    +--------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table  | Non_unique | Key_name                 | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +--------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | tokens | 0          | PRIMARY                  | 1            | id          | A         | 2           |          |        |      | BTREE      |         |               |
    | tokens | 1          | tokens_user_id_foreign   | 1            | user_id     | A         | 2           |          |        |      | BTREE      |         |               |
    +--------+------------+--------------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    

提交回复
热议问题