mysql引用表无效列,mysql innodb:describe表不显示列引用,什么显示它们?

CREATE TABLE accounts (

account_name VARCHAR(100) NOT NULL PRIMARY KEY

);

CREATE TABLE products (

product_id INTEGER NOT NULL PRIMARY KEY,

product_name VARCHAR(100)

);

CREATE TABLE bugs (

bug_id INTEGER NOT NULL PRIMARY KEY,

bug_description VARCHAR(100),

bug_status VARCHAR(20),

reported_by VARCHAR(100) REFERENCES accounts(account_name),

assigned_to VARCHAR(100) REFERENCES accounts(account_name),

verified_by VARCHAR(100) REFERENCES accounts(account_name)

);

CREATE TABLE bugs_products (

bug_id INTEGER NOT NULL REFERENCES bugs,

product_id INTEGER NOT NULL REFERENCES products,

PRIMARY KEY (bug_id, product_id)

);

if i execute 'describe bugs_products' i get:

Field | Type | Null | Key | Default | Extra |

+------------+---------+------+-----+---------+-------+

| bug_id | int(11) | NO | PRI | NULL | |

| product_id | int(11) | NO | PRI | NULL | |

+------------+---------+------+-----+---------+-------+

how can i also get references information?

解决方案

On testing, the foreign keys are not created on my machine using this syntax:

CREATE TABLE bugs (

...

reported_by VARCHAR(100) REFERENCES accounts(account_name),

...

) ENGINE = INNODB;

But they are when I use this create statement:

CREATE TABLE bugs (

...

reported_by VARCHAR(100),

...

FOREIGN KEY (reported_by) REFERENCES accounts(account_name)

) ENGINE = INNODB;

An easy way to see if foreign keys exist on a table is:

show create table bugs_products

Or you can query the information schema:

select

table_schema

, table_name

, column_name

, referenced_table_schema

, referenced_table_name

, referenced_column_name

from information_schema.KEY_COLUMN_USAGE

where table_name = 'bugs'

Also check you're using the InnoDB storage engine. The MyISAM engine does not support foreign keys. You can find the engine like:

select table_schema, table_name, engine

from information_schema.TABLES

where table_name = 'bugs'

If you try to create a foreign key on a MyISAM table, it will silently discard the references and pretend to succeed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值