List:General Discussion« Previous MessageNext Message »
From:Peter Brawley Date:April 6 2009 3:07pm
Subject:Re: One to many relationship
View as plain text  
Abdul,

Is this what you mean?

CREATE TABLE Table1 (
 table1_id INT UNSIGNED PRIMARY KEY AUTO INCREMENT,
entrydate TIMESTAMP
)ENGINE=INNODB;
CREATE TABLE table2 (
 table2_id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
 table1_id INT UNSIGNED NOT NULL,
 entrydate TIMESTAMP,
FOREIGN KEY(table1_id) REFERENCES table1(table1_id)
)ENGINE=INNODB;

After this, the DB engine will ensure that any table1_id value you try 
to insert in table2 actually exists in table1. See the manual page for 
foreign keys.

PB

-----

abdulazeez alugo wrote:
>  
>
>
>
>
> Hello all,
> I'm trying to design a relational database where two tables link to each other
> through unique id sa below
> Table 1
> table1_id INT UNSIGNED NOT NULL AUTO INCREMENT,
> entrydate TIMESTAMP
>  
> Table2
> table2_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
> table1_id INT UNSIGNED NOT NULL,
> entrydate TIMESTAMP,
>  
> Sorry. The above is just a rough sketch of what I have here and I hope you understand
> what I'm trying to portray but the value of table1_id inside table2 keeps returning the
> value 0 thereby it doesn't correspond with any value in table1_id in table1.
> Please I need help on this issue.
> Thanks in anticipation of your prompt response.
>
>
> _________________________________________________________________
> Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.
>
> http://www.microsoft.com/windows/windowslive/products/photos.aspx
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.0.238 / Virus Database: 270.11.42/2042 - Release Date: 04/05/09 10:54:00
>
>   
Thread
One to many relationshipabdulazeez alugo5 Apr
  • Re: One to many relationshipMartijn Tonies6 Apr
  • Re: One to many relationshipPeter Brawley6 Apr
    • RE: One to many relationshipabdulazeez alugo7 Apr