Dit betreft en top40 systeem. Ik heb daar een nieuw overzicht voor gemaakt met behulp van SQL Designer en daar heb ik nu enkele vragen over. Het uit gewerkte overzicht van de tabellen en velden vinden jullie onder aan.
Ik moet hier nu dus een INSERT, UPDATE en DELETE query voor maken. Maar hier heb ik al even op Google voor rond gesnuffeld maar ben nog weinig goede uitleggen tegen gekomen. Ik vraag me daarom ook af aan jullie hoe jullie deze query's zullen gaan oplossen?
Maar waar ik ook nog niet uitkom in het denk proces is het volgende.
Stel ik doe een nieuwe week INSERT nu is de kans heel erg groot dat er een deel van de artiesten en titels al in een vorige week is voor gekomen. Nu is het dus de bedoeling dat die rows niet extra worden aangemaakt. Hoe moet ik dit samen met z'n INSERT query oplossen?
CREATE TABLE `top40_titels` (
`titel_id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,
`artiest_id` INTEGER NULL DEFAULT NULL,
`titel_naam (150)` VARCHAR(150) NULL DEFAULT NULL,
`p_date` DATETIME NULL DEFAULT NULL,
`u_date` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`titel_id`, `artiest_id`)
);
CREATE TABLE `top40` (
`top40_id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,
`week` INTEGER NULL DEFAULT NULL,
`jaar` INTEGER NULL DEFAULT NULL,
`positie_h` INTEGER NULL DEFAULT NULL,
`titel_id` INTEGER NULL DEFAULT NULL,
`p_date` DATETIME NULL DEFAULT NULL,
`u_date` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`top40_id`, `week`, `jaar`, `positie_h`)
);
CREATE TABLE `top40_artiesten` (
`artiest_id` INTEGER NULL AUTO_INCREMENT DEFAULT NULL,
`artiest_naam (125)` VARCHAR(125) NULL DEFAULT NULL,
`p_date` DATETIME NULL DEFAULT NULL,
`u_date` DATETIME NULL DEFAULT NULL,
PRIMARY KEY (`artiest_id`)
);
ALTER TABLE `top40_titels` ADD FOREIGN KEY (artiest_id) REFERENCES `top40_artiesten` (`artiest_id`);
ALTER TABLE `top40` ADD FOREIGN KEY (titel_id) REFERENCES `top40_titels` (`titel_id`) ON DELETE CASCADE;
ALTER TABLE `top40` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ALTER TABLE `top40_titels` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
ALTER TABLE `top40_artiesten` ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;