Choose Your Language

Sunday, 15 November 2015

multiple foreignkey in a table

CREATE TABLE tbl_product(
   pk_product_id int(10) unsigned NOT NULL AUTO_INCREMENT,

   product_name varchar(45) NOT NULL,

   PRIMARY KEY (`pk_product_id`)

);

CREATE TABLE tbl_dealer(
   pk_dealer_id int(10) unsigned NOT NULL AUTO_INCREMENT,

   dealer_name varchar(45) NOT NULL,

   PRIMARY KEY (`pk_dealer_id`)

);

CREATE TABLE tbl_spare(
   pk_spare_id int(10) unsigned NOT NULL AUTO_INCREMENT,
 
  fk_product_id int(10) unsigned NOT NULL,
 
  fk_dealer_id int(10) unsigned NOT NULL,
 
  dealer_price varchar(45) NOT NULL,
 
  seller_price varchar(45) NOT NULL,
 
PRIMARY KEY (`pk_spare_id`),
 
FOREIGN KEY (fk_product_id ) REFERENCES tbl_product(pk_product_id),
FOREIGN KEY (fk_dealer_id ) REFERENCES tbl_dealer(pk_dealer_id )
);

No comments:

Post a Comment