A costo di allungare il post riporto la struttura.
E' ovvio che è un sistema per catalogare i miei cd e non è detto che finisca in rete.
Codice PHP:
-- Struttura della tabella `cd`
--
CREATE TABLE IF NOT EXISTS `cd` (
`id` int(11) NOT NULL auto_increment,
`titolo` varchar(255) NOT NULL,
`anno` year(4) NOT NULL,
`data_registrazione` date NOT NULL,
`prestito` varchar(255) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_etichette`
--
CREATE TABLE IF NOT EXISTS `cd_etichette` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`id_etichette` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_generi`
--
CREATE TABLE IF NOT EXISTS `cd_generi` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`id_generi` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_musicisti`
--
CREATE TABLE IF NOT EXISTS `cd_musicisti` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`id_musicisti` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_musicisti_autori`
--
CREATE TABLE IF NOT EXISTS `cd_musicisti_autori` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`id_musicisti` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_musicisti_strumenti`
--
CREATE TABLE IF NOT EXISTS `cd_musicisti_strumenti` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`id_musicisti_strumenti` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `cd_tracce`
--
CREATE TABLE IF NOT EXISTS `cd_tracce` (
`id` int(11) NOT NULL auto_increment,
`id_cd` int(11) NOT NULL,
`numero_traccia` int(3) NOT NULL,
`traccia` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `etichette`
--
CREATE TABLE IF NOT EXISTS `etichette` (
`id` int(11) NOT NULL auto_increment,
`etichetta` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `etichetta` (`etichetta`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `generi`
--
CREATE TABLE IF NOT EXISTS `generi` (
`id` int(11) NOT NULL auto_increment,
`genere` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `genere` (`genere`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `musicisti`
--
CREATE TABLE IF NOT EXISTS `musicisti` (
`id` int(11) NOT NULL auto_increment,
`musicista` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `musicista` (`musicista`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `musicisti_strumenti`
--
CREATE TABLE IF NOT EXISTS `musicisti_strumenti` (
`id` int(11) NOT NULL auto_increment,
`id_musicisti` int(11) NOT NULL,
`id_strumenti` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Struttura della tabella `strumenti`
--
CREATE TABLE IF NOT EXISTS `strumenti` (
`id` int(11) NOT NULL auto_increment,
`strumento` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `strumento` (`strumento`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Ho pensato ad una struttura che mi permettesse di associare al singolo titolo diversi valori per l'autore, per i musicisti, per l'etichetta e per il genere, perchè i casi sono innumerevoli ed associare due generi allo stesso cd può essere necessario. Inoltre ad ogni musicista mi deve permettere di associare gli strumenti suonati e personalizzarli per ogni cd, quindi se Elvin Jones è batterista in un cd può essere sia batterista che pianista in un altro cd. Il tutto deve potersi scegliere da elenchi di selezione multipli per evitarmi ogni volta di riscrivere le stesse cose. Ho cercato anche di suddivedere in molte tabelle, di cui alcune di collegamento, in modo che la struttura possa essere espansibile.