zoukankan      html  css  js  c++  java
  • 外键查询及删除

    ```
    SELECT Concat(TABLE_NAME, '.', COLUMN_NAME) AS 'foreign key',
    Concat(referenced_table_name, '.', referenced_column_name) AS 'references'
    FROM information_schema.key_column_usage
    WHERE table_schema = '$databasename'
    AND referenced_table_name IS NOT NULL;

    ```

    其中, '$databasename' 要替换成您要查询的那个数据库的名称。

    ```
    mysql> SHOW CREATE TABLE mk_big_sent_visitorG
    *************************** 1. row ***************************
    Table: mk_big_sent_visitor
    Create Table: CREATE TABLE `mk_big_sent_visitor` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `mk_big_sent_id` int(11) NOT NULL,
    `customer_id` int(11) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `fk_mk_big_sent_visitor_mk_big_sent1_idx` (`mk_big_sent_id`),
    KEY `fk_mk_big_sent_visitor_customer1_idx` (`customer_id`),
    CONSTRAINT `fk_mk_big_sent_visitor_customer1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
    CONSTRAINT `fk_mk_big_sent_visitor_mk_big_sent1` FOREIGN KEY (`mk_big_sent_id`) REFERENCES `mk_big_sent` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=''
    1 row in set (0.00 sec)
    ```


    删除外键:

    ```
    ALTER TABLE mk_prize DROP FOREIGN KEY fk_think_mk_prize_shopweb1,

    DROP FOREIGN KEY fk_mk_big_sent_visitor_mk_big_sent1;
    ```

  • 相关阅读:
    Codeforces 1515 H. Phoenix and Bits 题解
    Codeforces 1511 F. Chainword 题解
    Codeforces 1369F. BareLee 题解
    莫队学习笔记
    圆方树学习笔记
    虚树学习笔记
    NOIP2020退役记
    CSP-S2 2021 场外
    我。
    WC2021 游记
  • 原文地址:https://www.cnblogs.com/martinjinyu/p/4711756.html
Copyright © 2011-2022 走看看