日期:2014-05-16 浏览次数:20869 次
create table booking( o_id bigint(20) not null primary key, o_user int(10) not null, o_time varchar(50) not null, o_state varchar(10) not null, o_delivery varchar(50), o_ems varchar(20), o_number int(20), o_total float(6,2) not null, foreign key(o_user) references user(u_id) )engine=InnoDB charset=utf8; create table information( i_id int(10) not null auto_increment primary key, i_orderid bigint(20) not null, i_name varchar(50) not null, i_number int(10) not null, i_price float(6,2) not null, foreign key(i_orderid) references booking(o_id) //外键 )engine=InnoDB charset=utf8;
SELECT ke.referenced_table_name parent, ke.table_name child, ke.REFERENCED_COLUMN_NAME parent_column, ke.column_name child_column, ke.constraint_name FROM information_schema.KEY_COLUMN_USAGE ke WHERE ke.referenced_table_name IS NOT NULL and ke.referenced_table_name = 'booking' and ke.REFERENCED_COLUMN_NAME = 'o_id' and ke.REFERENCED_TABLE_SCHEMA = '你的数据库名字' ORDER BY ke.referenced_table_name;