Mysql - use primary key as foreign key
I have two tables that share a many-to-many relation, namely contig and path.
mysql> describe contig ;
+-------------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+----------------------+------+-----+---------+-------+
| id_contig | smallint(5) unsigned | NO | PRI | NULL | |
| length | smallint(5) unsigned | NO | | NULL | |
| total_rc | int(11) | NO | | NULL | |
| rc_es1 | smallint(6) | NO | | NULL | |
| rc_es2 | smallint(6) | NO | | NULL | |
| rc_ls1 | smallint(6) | NO | | NULL | |
| rc_ls2 | smallint(6) | NO | | NULL | |
| rpkm_es1 | float(10,2) | NO | | NULL | |
| rpkm_es2 | float(10,2) | NO | | NULL | |
| rpkm_ls1 | float(10,2) | NO | | NULL | |
| rpkm_ls2 | float(10,2) | NO | | NULL | |
| hit_id_nr | varchar(50) | YES | | NULL | |
| hit_id_tair | varchar(50) | YES | | NULL | |
| hit_id_uniprot | varchar(50) | YES | | NULL | |
| hit_desc_nr | text | YES | | NULL | |
| hit_desc_tair | text | YES | | NULL | |
| hit_desc_uniprot | text | YES | | NULL | |
| bayseq_likelihood | float(11,9) | YES | | NULL | |
| bayseq_fdr | float(11,9) | YES | | NULL | |
| deseq_fc | float(10,2) | YES | | NULL | |
| deseq_log2fc | float(10,2) | YES | | NULL | |
| deseq_pval | double | YES | | NULL | |
| deseq_padj | double | YES | | NULL | |
| edger_logconc | double | YES | | NULL | |
| edger_log2fc | double | YES | | NULL | |
| edger_pval | double | YES | | NULL | |
| edger_fdr | double | YES | | NULL | |
+-------------------+----------------------+------+-----+---------+-------+
and
mysql> describe path ;
+-----------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+---------+-------+
| id_path | tinyint(3) unsigned | NO | PRI | NULL | |
| path_name | text | NO | | NULL | |
| path_nseq | smallint(5) unsigned | NO | | NULL | |
| path_map | varchar(8) | NO | | NULL | |
| path_pix | varchar(28) | NO | | NULL | |
+-----------+----------------------+------+-----+---------+-------+
In order to link them, I created a "cross table", namely contig2path :
mysql> describe contig2path ;
+-----------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------------------+------+-----+---------+-------+
| id_contig | smallint(5) unsigned | NO | PRI | NULL | |
| id_path | tinyint(3) unsigned | NO | PRI | NULL | |
+-----------+----------------------+------+-----+---------+-------+
As you probably imagine, I would like to use contig2path to link data from
tables contig and path. But before using any JOIN, I have to link tables
with foreign keys.
-> contig.id_contig would be linked to conti2path.id_contig
-> path.id_path would be linked to contig2path.id_path
My question is : how could I make the primary keys to be also foreign keys ?
No comments:
Post a Comment