# MySQL-Front 3.1  (Build 14.13)


# Host: localhost    Database: multiproprieta
# ------------------------------------------------------
# Server version 4.1.8-nt

#
# Table structure for table clienti
#

CREATE TABLE `clienti` (
  `Id_Cliente` int(10) unsigned NOT NULL default '0',
  `Nome` varchar(40) NOT NULL default '',
  `Cognome` varchar(40) NOT NULL default '',
  PRIMARY KEY  (`Id_Cliente`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table clienti
#

INSERT INTO `clienti` VALUES (1,'Mario','Rossi');
INSERT INTO `clienti` VALUES (2,'Maria','Bianchi');
INSERT INTO `clienti` VALUES (3,'Carlo','Verdi');

#
# Table structure for table immobili
#

CREATE TABLE `immobili` (
  `Id_Immobile` int(10) unsigned NOT NULL default '0',
  `Metri_quadrati` smallint(6) NOT NULL default '0',
  `Tipologia` enum('lusso','medio','spartano') default NULL,
  `Id_Insediamento` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Immobile`),
  KEY `Id_Insediamento` (`Id_Insediamento`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table immobili
#

INSERT INTO `immobili` VALUES (1,100,'lusso',1);
INSERT INTO `immobili` VALUES (2,80,'medio',1);
INSERT INTO `immobili` VALUES (3,120,'lusso',2);
INSERT INTO `immobili` VALUES (4,70,'medio',3);

#
# Table structure for table insediamenti
#

CREATE TABLE `insediamenti` (
  `Id_Insediamento` int(10) unsigned NOT NULL default '0',
  `Id_Localita` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Insediamento`),
  KEY `Id_Localita` (`Id_Localita`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table insediamenti
#

INSERT INTO `insediamenti` VALUES (1,1);
INSERT INTO `insediamenti` VALUES (2,1);
INSERT INTO `insediamenti` VALUES (3,2);

#
# Table structure for table localita
#

CREATE TABLE `localita` (
  `Id_Localita` int(10) unsigned NOT NULL default '0',
  `Nome_Localita` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`Id_Localita`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table localita
#

INSERT INTO `localita` VALUES (1,'Savona');
INSERT INTO `localita` VALUES (2,'Rapallo');

#
# Table structure for table periodi
#

CREATE TABLE `periodi` (
  `Id_Periodo` int(10) unsigned NOT NULL default '0',
  `Periodo` enum('inverno','primavera','estate','autunno') default NULL,
  PRIMARY KEY  (`Id_Periodo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table periodi
#

INSERT INTO `periodi` VALUES (1,'inverno');
INSERT INTO `periodi` VALUES (2,'primavera');
INSERT INTO `periodi` VALUES (3,'estate');
INSERT INTO `periodi` VALUES (4,'autunno');

#
# Table structure for table prezzi
#

CREATE TABLE `prezzi` (
  `Id_Prezzo` int(10) unsigned NOT NULL default '0',
  `Coefficiente_Prezzo` float NOT NULL default '0',
  `Id_Localita` int(10) unsigned NOT NULL default '0',
  `Id_Periodo` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Prezzo`),
  KEY `Id_Localita` (`Id_Localita`),
  KEY `Id_Periodo` (`Id_Periodo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table prezzi
#

INSERT INTO `prezzi` VALUES (1,1,1,1);
INSERT INTO `prezzi` VALUES (2,1.5,1,2);
INSERT INTO `prezzi` VALUES (3,2,2,3);
INSERT INTO `prezzi` VALUES (4,1.2,2,4);

#
# Table structure for table proprieta
#

CREATE TABLE `proprieta` (
  `Id_Proprieta` int(10) unsigned NOT NULL default '0',
  `Prezzo_Vendita` decimal(8,2) default NULL,
  `Prezzo_Affitto` decimal(8,2) default NULL,
  `Id_Immobile` int(10) unsigned NOT NULL default '0',
  `Id_Cliente_Proprieta` int(10) unsigned NOT NULL default '0',
  `Id_Cliente_Affitto` int(10) unsigned default NULL,
  PRIMARY KEY  (`Id_Proprieta`),
  KEY `Id_Immobile` (`Id_Immobile`),
  KEY `Id_Cliente_Proprieta` (`Id_Cliente_Proprieta`),
  KEY `Id_Cliente_Affitto` (`Id_Cliente_Affitto`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table proprieta
#

INSERT INTO `proprieta` VALUES (1,NULL,NULL,1,1,NULL);
INSERT INTO `proprieta` VALUES (2,NULL,NULL,2,2,NULL);
INSERT INTO `proprieta` VALUES (3,NULL,NULL,3,2,NULL);
INSERT INTO `proprieta` VALUES (4,NULL,NULL,4,3,NULL);

#
# Table structure for table scambi
#

CREATE TABLE `scambi` (
  `Id_Scambi` int(10) unsigned NOT NULL auto_increment,
  `Id_Proprieta1` int(10) unsigned NOT NULL default '0',
  `Id_Proprieta2` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Scambi`),
  KEY `Id_Proprieta1` (`Id_Proprieta1`),
  KEY `Id_Proprieta2` (`Id_Proprieta2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table scambi
#


#
# Table structure for table settimane
#

CREATE TABLE `settimane` (
  `Id_Settimana` int(10) unsigned NOT NULL default '0',
  `Id_Periodo` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Settimana`),
  KEY `Id_Periodo` (`Id_Periodo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table settimane
#

INSERT INTO `settimane` VALUES (1,1);
INSERT INTO `settimane` VALUES (2,1);
INSERT INTO `settimane` VALUES (3,1);
INSERT INTO `settimane` VALUES (4,1);
INSERT INTO `settimane` VALUES (5,1);
INSERT INTO `settimane` VALUES (6,2);
INSERT INTO `settimane` VALUES (7,2);
INSERT INTO `settimane` VALUES (8,3);
INSERT INTO `settimane` VALUES (9,3);
INSERT INTO `settimane` VALUES (10,3);
INSERT INTO `settimane` VALUES (11,4);
INSERT INTO `settimane` VALUES (12,4);

#
# Table structure for table settimane_proprieta
#

CREATE TABLE `settimane_proprieta` (
  `Id_Settimane` int(10) unsigned NOT NULL default '0',
  `Id_Proprieta` int(10) unsigned NOT NULL default '0',
  PRIMARY KEY  (`Id_Settimane`,`Id_Proprieta`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

#
# Dumping data for table settimane_proprieta
#

INSERT INTO `settimane_proprieta` VALUES (1,1);
INSERT INTO `settimane_proprieta` VALUES (1,2);
INSERT INTO `settimane_proprieta` VALUES (2,1);
INSERT INTO `settimane_proprieta` VALUES (2,2);
INSERT INTO `settimane_proprieta` VALUES (3,1);
INSERT INTO `settimane_proprieta` VALUES (3,2);
INSERT INTO `settimane_proprieta` VALUES (4,2);
INSERT INTO `settimane_proprieta` VALUES (7,4);
INSERT INTO `settimane_proprieta` VALUES (8,4);
INSERT INTO `settimane_proprieta` VALUES (10,3);
INSERT INTO `settimane_proprieta` VALUES (11,3);

#
#  Foreign keys for table immobili
#

ALTER TABLE `immobili`
  ADD FOREIGN KEY (`Id_Insediamento`) REFERENCES `insediamenti` (`Id_Insediamento`);

#
#  Foreign keys for table insediamenti
#

ALTER TABLE `insediamenti`
  ADD FOREIGN KEY (`Id_Localita`) REFERENCES `localita` (`Id_Localita`);

#
#  Foreign keys for table prezzi
#

ALTER TABLE `prezzi`
  ADD FOREIGN KEY (`Id_Localita`) REFERENCES `localita` (`Id_Localita`),
  ADD FOREIGN KEY (`Id_Periodo`) REFERENCES `periodi` (`Id_Periodo`);

#
#  Foreign keys for table proprieta
#

ALTER TABLE `proprieta`
  ADD FOREIGN KEY (`Id_Immobile`) REFERENCES `immobili` (`Id_Immobile`),
  ADD FOREIGN KEY (`Id_Cliente_Proprieta`) REFERENCES `clienti` (`Id_Cliente`),
  ADD FOREIGN KEY (`Id_Cliente_Affitto`) REFERENCES `clienti` (`Id_Cliente`);

#
#  Foreign keys for table scambi
#

ALTER TABLE `scambi`
  ADD FOREIGN KEY (`Id_Proprieta1`) REFERENCES `proprieta` (`Id_Proprieta`),
  ADD FOREIGN KEY (`Id_Proprieta2`) REFERENCES `proprieta` (`Id_Proprieta`);

#
#  Foreign keys for table settimane
#

ALTER TABLE `settimane`
  ADD FOREIGN KEY (`Id_Periodo`) REFERENCES `periodi` (`Id_Periodo`);

