Doomed to Wordpress

Serious Reflections During the Life of Jeremy Fisher

   

Subscribe
Subscribe to a syndicated feed of my weblog, brought to you by the wonders of RSS.

Flavours
There's more than one way to view this weblog; try these flavours on for size.

  • index
  • circa 1993
  • RSS
  • Links
    These are a few links to my other sites.

  • Ставропигиальныя Пластинки
  • Анкылым
  • Русское Шрифтовое Зало
  • Gopher (Proxied)
  • More about Gopher
  •        

    2020/11/03 mysql foreign keys

    Показать внешние ключи, ссылающиеся на таблицу:

    SELECT
        TABLE_NAME,
        COLUMN_NAME,
        CONSTRAINT_NAME,
        REFERENCED_TABLE_NAME,
        REFERENCED_COLUMN_NAME
    FROM
        INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    WHERE
        REFERENCED_TABLE_SCHEMA = 'db_name' AND REFERENCED_TABLE_NAME = 'table_name';
    

    На столбец:

    SELECT
        TABLE_NAME,
        COLUMN_NAME,
        CONSTRAINT_NAME,
        REFERENCED_TABLE_NAME,
        REFERENCED_COLUMN_NAME
    FROM
        INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    WHERE
        REFERENCED_TABLE_SCHEMA = 'db_name'
        AND REFERENCED_TABLE_NAME = 'table_name'
        AND REFERENCED_COLUMN_NAME = 'column_name';
    

    Source: https://tableplus.com/blog/2018/08/mysql-how-to-see-foreign-key-relationship-of-a-table.html

    #mysql

    permanent link