-2
我怎樣才能獲得外鍵字段在phpMyAdmin中使用php和mysqli?
見照片:如何獲得字段外鍵(表和字段)php mysqli
我怎樣才能獲得外鍵字段在phpMyAdmin中使用php和mysqli?
見照片:如何獲得字段外鍵(表和字段)php mysqli
所有的約束都列在INFORMATION_SCHEMA.TABLE_CONSTRAINTS:
mysql> create table test.foo (id int primary key);
mysql> create table test.bar (fooid int, foreign key (fooid) references foo(id));
mysql> select * from information_schema.table_constraints
where constraint_schema = 'test'\G
*************************** 1. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: bar_ibfk_1
TABLE_SCHEMA: test
TABLE_NAME: bar
CONSTRAINT_TYPE: FOREIGN KEY
*************************** 2. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: PRIMARY
TABLE_SCHEMA: test
TABLE_NAME: foo
CONSTRAINT_TYPE: PRIMARY KEY
而且所有這些約束的列是INFORMATION_SCHEMA.KEY_COLUMN_USAGE:
mysql> select * from information_schema.key_column_usage
where constraint_schema = 'test'\G
*************************** 1. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: bar_ibfk_1
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: bar
COLUMN_NAME: fooid
ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: 1
REFERENCED_TABLE_SCHEMA: test
REFERENCED_TABLE_NAME: foo
REFERENCED_COLUMN_NAME: id
*************************** 2. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: PRIMARY
TABLE_CATALOG: def
TABLE_SCHEMA: test
TABLE_NAME: foo
COLUMN_NAME: id
ORDINAL_POSITION: 1
POSITION_IN_UNIQUE_CONSTRAINT: NULL
REFERENCED_TABLE_SCHEMA: NULL
REFERENCED_TABLE_NAME: NULL
REFERENCED_COLUMN_NAME: NULL
感謝幫助了很多) – KoSMoS 2013-02-24 18:25:26
「獲取外鍵領域」是什麼意思? – 2013-02-24 17:40:07
@Explosion Pills喜歡圖片我想獲得device.devicetype.id – KoSMoS 2013-02-24 17:42:20