Skip navigation links

MySQL Forums :: Foreign Keys (Referential Integrity) :: 2 Columns as PK, Refering by FK to one of them and over another table to the other...


Advanced Search

Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other...
Posted by: Daniel Jäger ()
Date: January 06, 2011 08:30AM

Hi Chad,

once again, thank you for the example.

I've set it up the first approach you've shown.

http://img828.imageshack.us/img828/3631/ermsecondtry.png


CREATE TABLE IF NOT EXISTS `vat` (
`vat_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`start_date` DATETIME NOT NULL ,
`end_date` DATETIME NULL ,
`rate` DECIMAL(6,2) NULL ,
`replaced_vat` INT UNSIGNED NULL ,
PRIMARY KEY (`vat_id`) ,
CONSTRAINT `vat_replaced_vat`
FOREIGN KEY (`replaced_vat` )
REFERENCES `vat` (`vat_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


CREATE TABLE IF NOT EXISTS `country_vat` (
`iso` CHAR(2) NOT NULL ,
`vat` INT UNSIGNED NOT NULL ,
PRIMARY KEY (`iso`, `vat`) ,
CONSTRAINT `country_vat_vat`
FOREIGN KEY (`vat` )
REFERENCES `vat` (`vat_id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `country_vat_iso`
FOREIGN KEY (`iso` )
REFERENCES `country` (`iso` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;


... and added a "replaced_vat" field to see the history which vat gets replace by a new one. So on a certain date the system can recognize the vat switch and notify the user before he starts to write any invoices.

Looks good?! :)

Daniel

Options: ReplyQuote


Subject Views Written By Posted
2 Columns as PK, Refering by FK to one of them and over another table to the other... 3641 Daniel Jäger 01/05/2011 08:44AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1079 Chad Bourque 01/05/2011 10:23AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1103 Daniel Jäger 01/05/2011 03:48PM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1704 Chad Bourque 01/05/2011 06:43PM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1140 Daniel Jäger 01/06/2011 08:30AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1032 Chad Bourque 01/06/2011 11:05AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1073 Daniel Jäger 01/10/2011 04:19AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1093 Chad Bourque 01/10/2011 08:06AM
Re: 2 Columns as PK, Refering by FK to one of them and over another table to the other... 1348 Daniel Jäger 01/11/2011 08:02AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.